You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Mufaddal Khumri <mk...@allegrocentral.com> on 2008/01/04 17:56:28 UTC
Accessing form parameters in an interceptor ....
Basically I am trying to access some parameters in an interceptor
since the interceptor needs to do something based on the values of
these parameters. Any action that this interceptor is applied to does
not need these parameters.
In order to do this:
If I have an ftl file with a form like such:
<@s.form namespace="/ob" action="test" method="post">
<@s.textfield name="param1" label="Param1" />
<@s.textfield name="param2" label="Param2" />
<@s.submit value="Send"/>
</...@s.form>
The html produced by the above code is:
<form id="test" name="test" onsubmit="return true;" action="/mywebapp/
ob/test.action" method="post">
<table class="wwFormTable">
<tr>
<td class="tdLabel"><label for="test_param1"
class="label">Param1:</label></td>
<td><input type="text" name="param1" value="" id="test_param1"/
></td>
</tr>
<tr>
<td class="tdLabel"><label for="test_param2"
class="label">Param2:</label></td>
<td><input type="text" name="param2" value="" id="test_param2"/
></td>
</tr>
<tr>
<td colspan="2"><div align="right"><input type="submit"
id="test_0" value="Send"/></div></td>
</tr>
</table></form>
Next since I need to see the values of these parameters in an
interceptor and any actions that this interceptor does not need these
parameters set as properties in the Action POJO; I implement the
NoParameter interface in my TestAction. (If I do not do this struts
complains that it cannot set these properties in my action POJO.
Ideally I would like to achieve the functionality I am looking to get
without forcing the action class to implement the NoParameter marker
interface?? Is there a way to do this??)
In my interceptor how do I get access to these parameters?
If I do something like this:
String param1 = actionInvocation.getStack().findString('param1');
String param2 = actionInvocation.getStack().findString('param2');
I get null values for param1 and param2
Aren't form parameters accessible from the value stack?
Thanks for any pointers.
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: Accessing form parameters in an interceptor ....
Posted by Chris Pratt <th...@gmail.com>.
Try using InvocationContext.getActionContext().getParameters(). That
will give you a Map containing all the parameters. I believe if you
remove parameters from the map, they won't be injected into the
Action, but you'll have to try that to confirm.
(*Chris*)
On Jan 4, 2008 8:56 AM, Mufaddal Khumri <mk...@allegrocentral.com> wrote:
> Basically I am trying to access some parameters in an interceptor
> since the interceptor needs to do something based on the values of
> these parameters. Any action that this interceptor is applied to does
> not need these parameters.
>
> In order to do this:
>
> If I have an ftl file with a form like such:
>
> <@s.form namespace="/ob" action="test" method="post">
>
> <@s.textfield name="param1" label="Param1" />
> <@s.textfield name="param2" label="Param2" />
> <@s.submit value="Send"/>
>
> </...@s.form>
>
> The html produced by the above code is:
>
> <form id="test" name="test" onsubmit="return true;" action="/mywebapp/
> ob/test.action" method="post">
> <table class="wwFormTable">
> <tr>
> <td class="tdLabel"><label for="test_param1"
> class="label">Param1:</label></td>
> <td><input type="text" name="param1" value="" id="test_param1"/
> ></td>
> </tr>
> <tr>
> <td class="tdLabel"><label for="test_param2"
> class="label">Param2:</label></td>
> <td><input type="text" name="param2" value="" id="test_param2"/
> ></td>
> </tr>
> <tr>
> <td colspan="2"><div align="right"><input type="submit"
> id="test_0" value="Send"/></div></td>
> </tr>
> </table></form>
>
> Next since I need to see the values of these parameters in an
> interceptor and any actions that this interceptor does not need these
> parameters set as properties in the Action POJO; I implement the
> NoParameter interface in my TestAction. (If I do not do this struts
> complains that it cannot set these properties in my action POJO.
> Ideally I would like to achieve the functionality I am looking to get
> without forcing the action class to implement the NoParameter marker
> interface?? Is there a way to do this??)
>
> In my interceptor how do I get access to these parameters?
>
> If I do something like this:
> String param1 = actionInvocation.getStack().findString('param1');
> String param2 = actionInvocation.getStack().findString('param2');
>
> I get null values for param1 and param2
>
> Aren't form parameters accessible from the value stack?
>
> Thanks for any pointers.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org