You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Brad A Cupit <br...@lsu.edu> on 2008/04/17 17:22:26 UTC
return Result instantiated within Action
[creating a new thread so as not to hijack the
"ServletRedirectActionResult - is there a way to set parameters?"
thread]
Don Brown said:
>> The easiest solution is to simply return a
>> ServletActionRedirectResult instance from
>> your action method.
I've tried that myself as it seemed a very clean way of returning a
result, but I get a NullPointerException since the ActionMapper isn't
set on the Result. Now I could instead add:
@Inject
public void setActionMapper(ActionMapper actionMapper) { ... }
to my Action, then return a new ServletActionRedirectResult, but the
calling syntax gets a little messy. Here's an example method in the
Action class:
public Result submit() throws Exception {
ServletActionRedirectResult result = new
ServletActionRedirectResult("actionName").addParameter(
"param1", "${value1}");
result.setActionMapper(actionMapper);
return result;
}
Can you think of any way that the actionMapper could be set
automatically on Result's which are instantiated inside of an Action? If
not, should I file this as a feature request?
p.s. for others reading this, this approach would imply not implementing
the Action interface's execute() method, since it must return a String.
Instead you can just define any zero-arg public method and it can return
either a String or a Result, and your URLs can use the
actionName!method.action style for referencing a particular method on
the Action.
Brad Cupit
Louisiana State University - UIS
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
RE: return Result instantiated within Action
Posted by Brad A Cupit <br...@lsu.edu>.
>> Ah, good point. Yes, please file this as a request, as it
>> should be pretty easy to do and would make things much easier.
done, thanks!
automatically set ActionMapper for ServletRedirectResult
https://issues.apache.org/struts/browse/WW-2598
Brad Cupit
Louisiana State University - UIS
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: return Result instantiated within Action
Posted by Don Brown <do...@gmail.com>.
On Fri, Apr 18, 2008 at 1:22 AM, Brad A Cupit <br...@lsu.edu> wrote:
> I've tried that myself as it seemed a very clean way of returning a
> result, but I get a NullPointerException since the ActionMapper isn't
> set on the Result.
> <snip />
> Can you think of any way that the actionMapper could be set
> automatically on Result's which are instantiated inside of an Action? If
> not, should I file this as a feature request?
Ah, good point. Yes, please file this as a request, as it should be
pretty easy to do and would make things much easier.
Don
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org