[ 
https://issues.apache.org/struts/browse/WW-2598?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=43635#action_43635
 ] 

Jeromy Evans commented on WW-2598:
----------------------------------

I agree with the issue but not with the proposed approach.  We shouldn't 
instantiate the Result ourselves using the *new* operator.
Instead we should be asking the Container's ObjectFactory to create a Result 
with the necessary dependences already injected.

That should be simple, but it's not.  

The ObjectFactory includes a buildResult method but it's not appropriate for 
use in an action.
Result result = objectFactory.buildResult(resultConfig, 
invocationContext.getContextMap());

Alternate proposal: expose a new API that requests the container to create a 
result.

The least effort would be something like this:
eg. return ResultBuilder.createResult("redirectAction").withParam("actionName", 
"${value1}");
where ResultBuilder either provides a static factory method or an instance can 
injected into the action 

(I'm not sure if the container supports static injection)



> automatically set ActionMapper for ServletRedirectResult
> --------------------------------------------------------
>
>                 Key: WW-2598
>                 URL: https://issues.apache.org/struts/browse/WW-2598
>             Project: Struts 2
>          Issue Type: Improvement
>          Components: Core Actions
>            Reporter: Brad Cupit
>            Priority: Minor
>
> when a ServletRedirectResult (or a subclass of it, like 
> ServletRedirectActionResult) is instantiated and returned as the Result for 
> the Action, the ActionMapper must be manually set by the developer. So, 
> instead of this
> // ideal situation
> public Result submit() {
>       return new 
> ServletActionRedirectResult("actionName").addParameter("param1", "${value1}");
> }
> the user must code this:
> // manually set the ActionMapper
> public Result submit() throws Exception {
>       ServletActionRedirectResult result = new 
> ServletActionRedirectResult("actionName").addParameter("param1", "${value1}");
>       result.setActionMapper(actionMapper);
>       return result;
> }
> and to get the ActionMapper in the Action, you have to add this setter:
> @Inject
> public void setActionMapper(ActionMapper actionMapper) { ... }
> This is a feature request/improvement so that the ActionMapper can be 
> automatically set in (or looked up by) the ServletRedirectResult.
> see this mailing list post:
> http://article.gmane.org/gmane.comp.jakarta.struts.user/155271
> and this reply by Don Brown:
> http://article.gmane.org/gmane.comp.jakarta.struts.user/155272

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply via email to