You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Stephen Turner <st...@MIT.EDU> on 2010/06/16 23:23:51 UTC

Redirect in an interceptor


We are investigating moving from Struts 2.0.x to 2.1.8. We have an  
interceptor that does a redirect like this:

    ResultConfig cfg = new ResultConfig("shRes",  
ServletRedirectResult.class.getName());
    cfg.addParam("location", "MyAction.action?"+request.getQueryString());
    actionInvocation.getProxy().getConfig().addResultConfig(cfg);
    return "shRes";

In upgrading (which involves going from xwork 2.0.4 -> 2.1.6) I found that  
the ResultConfig constructors are now protected and that there's a  
ResultConfig.Builder class that is used to create a ResultConfig object.  
That gets me to:

    ResultConfig.Builder configBldr = new ResultConfig.Builder("shRes",  
ServletRedirectResult.class.getName());
    configBldr.addParam("location",  
"MyAction.action?"+request.getQueryString());
    ResultConfig cfg = configBldr.build();
    actionInvocation.getProxy().getConfig().addResultConfig(cfg);
    return "shRes";

However, this won't compile because ActionConfig no longer provides a  
addResultConfig() method. I can't find any info on the Open Symphony site  
or through Google that tells me how to do what I want in the new world.  
Can anyone point me in the right direction?

Thanks,
Steve

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Redirect in an interceptor

Posted by Stephen Turner <st...@MIT.EDU>.
To answer my own question, just in case anyone comes across this:

It's no longer possible to dynamically alter the configuration, so a  
redirect to an action that's not in the config must be done differently. I  
copied the idea from ExecuteAndWaitInterceptor.java:

   ServletRedirectResult shRes = new ServletRedirectResult();
   container.inject(shRes);
   shRes.setLocation("MyAction.action?"+request.getQueryString());
   shRes.setPrependServletContext(true);
   shRes.execute(actionInvocation);
   return Action.NONE;

and up above:

     private Container container;

     @Inject
     public void setContainer(Container container) {
         this.container = container;
     }

Steve


On Wed, 16 Jun 2010 17:23:51 -0400, Stephen Turner <st...@mit.edu> wrote:

>
>
> We are investigating moving from Struts 2.0.x to 2.1.8. We have an
> interceptor that does a redirect like this:
>
>     ResultConfig cfg = new ResultConfig("shRes",
> ServletRedirectResult.class.getName());
>     cfg.addParam("location",  
> "MyAction.action?"+request.getQueryString());
>     actionInvocation.getProxy().getConfig().addResultConfig(cfg);
>     return "shRes";
>
> In upgrading (which involves going from xwork 2.0.4 -> 2.1.6) I found  
> that
> the ResultConfig constructors are now protected and that there's a
> ResultConfig.Builder class that is used to create a ResultConfig object.
> That gets me to:
>
>     ResultConfig.Builder configBldr = new ResultConfig.Builder("shRes",
> ServletRedirectResult.class.getName());
>     configBldr.addParam("location",
> "MyAction.action?"+request.getQueryString());
>     ResultConfig cfg = configBldr.build();
>     actionInvocation.getProxy().getConfig().addResultConfig(cfg);
>     return "shRes";
>
> However, this won't compile because ActionConfig no longer provides a
> addResultConfig() method. I can't find any info on the Open Symphony site
> or through Google that tells me how to do what I want in the new world.
> Can anyone point me in the right direction?
>
> Thanks,
> Steve
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>


-- 
Stephen Turner
Senior Programmer/Analyst - MIT IS&T

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org