Question

I have this action with wildcards:

@Namespace("/posts")
public class SearchPostBeansAction extends ActionSupport{
    private static final long serialVersionUID = 1L;
    private static Logger logger = Logger.getLogger(SearchPostBeansAction.class); 
    
    @Override
    @Actions({
        @Action(value="/{search1}/{param1}/",results={ 
            @Result(name=ACTION_SUCCESS,location="classic.main.general", type="tiles")})    
    })
    public String execute() throws Exception {
           logger.info("Action: " + getInvocatedURL() );
           String forward = SUCCESS;
           logger.info("getSearch1( " + getSearch1() + " )");
           logger.info("getParam1( " + getParam1() + " )");
           return forward;
    }
}

The result executed:

 - INFO (com.silver.front.view.actions.SearchPostBeansAction) - Action:
   /posts/category/cars/
   
 - INFO (com.silver.front.view.actions.SearchPostBeansAction) -   
   getSearch1( category )

 - INFO (com.silver.front.view.actions.SearchPostBeansAction) -   
   getParam1( cars )

If I intercept that action:

@InterceptorRef("seoFilter")
@Namespace("/anuncios")
public class SearchPostBeansAction extends ActionSupport{
    private static final long serialVersionUID = 1L;
...
}

The result executed:

 - INFO (com.silver.front.view.actions.SearchPostBeansAction) - Action:
   /posts/category/cars/
   
 - INFO (com.silver.front.view.actions.SearchPostBeansAction) -   
   getSearch1( null )

 - INFO (com.silver.front.view.actions.SearchPostBeansAction) -   
   getParam1( null) 

Why lost wildcard's parameters?

Here it´s interceptor:

public class SEOFilter implements Interceptor{
    private static final long serialVersionUID = 1L;
    private static Logger logger = Logger.getLogger(SEOFilter.class); 
    
    ActionSupport actionSupport = null;
    
    public String intercept(ActionInvocation invocation) throws Exception {
        actionSupport = (ActionSupport) invocation.getAction();
        actionSupport.execute();
    }
}
Was it helpful?

Solution 3

I got what I wanted!!! :)

Many Thanks Boris and Roman.

I just define a interceptor-stack.

<interceptors> 
    <interceptor name="seoFilter" class="com.silver.usaditos.admin.SEOFilter"></interceptor>
    <interceptor-stack name="defaultInterceptorStack">
        <interceptor-ref name="defaultStack"/>
        <interceptor-ref name="seoFilter"/>
    </interceptor-stack>
</interceptors>

OTHER TIPS

This is because you bypass all of the interceptors on the interceptor stack.

To use an Interceptor you need to call invocation.invoke() to tell struts to continue processing the request through the rest of the Interceptor stack.

You manually invoke the action thereby bypassing the interceptor stack.

public String intercept(ActionInvocation invocation) throws Exception {
    return invocation.invoke;
}

The error is you applied @InterceptorRef("seoFilter") to the action class and as you should know by convention it's applied to all actions in the class. Remove this and if you want to add a custom interceptor to the action use the @Action annotation.

@Action(value="/{search1}/{param1}/", results={ 
        @Result(name=ACTION_SUCCESS,location="classic.main.general", type="tiles")},
   interceptorRefs={@InterceptorRef("seoFilter"),@InterceptorRef("defaultStack")
})    

Assumed that seoFilter is a valid interceptor that will not break the stack.

This is the code for a valid interceptor

public String intercept(ActionInvocation invocation) throws Exception {
    // here you can place the code that used to intercept the action
    ...
    //finally
    return invocation.invoke();
}

As you didn't post the struts.xml and I cannot see how did you configure Struts to use with wildcard mappings I will provide you a reference for advanced wildcards from the documentation page to do it yourself.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top