You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by fea jabi <zy...@hotmail.com> on 2006/09/19 21:43:37 UTC
form-property value set in dispatch action is lost
In struts config have a Dynavalidator form-bean
<form-bean name="Form1" type=".... DynaValidatorForm">
<form-property name="typeName" type="java.lang.String"/>
......
</form-bean>
have prepare(Action) and dispath(LookupDispatchAction) actions for the jsp
in the config which are session scoped.
<action
path="/PrepareAction"
type="com.PrepareAction"
name="Form1"
scope="session">
<forward name="success" path="/pages/Accounts.jsp"
redirect="false"/>
</action>
<action
path="/DispatchAction"
type="com.DispatchAction"
name="Form1"
scope="session"
parameter="method">
<forward name="successCalc" path="/PrepareAction.do"
redirect="false"/>
</action>
In the jsp have a submit button which dispatches to the dispatch action to
one of the methods in it.
I am setting one of the form property value in that method.
public class DispatchAction extends LookupDispatchAction {
protected Map getKeyMethodMap() {
Map map = new HashMap();
map.put("btn.calc", "calc");
}
public ActionForward calculate(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
throws IOException, ServletException {
DynaValidatorForm frm = (DynaValidatorForm)form;
frm.set("typeName", "xxxxx");
return mapping.findForward("successCalc");
}
}
setting the form-property value in the dispatch action i.e the "typeName" to
"xxxxx"
When it is sucess it is going back to the prepare action and the form
property value is "" instead of "xxxxx". checked at the first statement in
the execute method in prepare action the form-property value is different.
not sure why the form-property value is different in prepare action as
before. When in dispatch action the form-bean had the right value i.e the
form-property in form-bean to "xxxxx". but when came to prepare it's value
is lost.
why is this happenning? how can this be fixed?
Thanks.
_________________________________________________________________
Express yourself - download free Windows Live Messenger themes!
http://clk.atdmt.com/MSN/go/msnnkwme0020000001msn/direct/01/?href=http://imagine-msn.com/themes/vibe/default.aspx?locale=en-us&source=hmtagline
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: form-property value set in dispatch action is lost
Posted by fea jabi <zy...@hotmail.com>.
thanks a lot that worked. I never understood what the "redirect" does until
now. I know now when to make it true.
Thanks a lot again.
>From: "Michael Jouravlev" <jm...@gmail.com>
>Reply-To: "Struts Users Mailing List" <us...@struts.apache.org>
>To: "Struts Users Mailing List" <us...@struts.apache.org>
>Subject: Re: form-property value set in dispatch action is lost
>Date: Wed, 20 Sep 2006 15:34:46 -0700
>
>You use the same form in both actions, and you chain them without a
>redirect, so the request parameters are applied to your form again
>when you forward to PrepareAction.
>
>Struts repopulates your form with request parameters, so if the
>parameter is mentioned in the request and it is emply, Struts will
>clear the value you've set.
>
>Also check your reset() method, Struts will call it before populating
>the form. This method is called from both of your actions, and you
>should not clear your form if PrepareAction is called.
>
>On 9/19/06, fea jabi <zy...@hotmail.com> wrote:
>>In struts config have a Dynavalidator form-bean
>>
>><form-bean name="Form1" type=".... DynaValidatorForm">
>> <form-property name="typeName" type="java.lang.String"/>
>>......
>></form-bean>
>>
>>have prepare(Action) and dispath(LookupDispatchAction) actions for the jsp
>>in the config which are session scoped.
>>
>><action
>> path="/PrepareAction"
>> type="com.PrepareAction"
>> name="Form1"
>> scope="session">
>> <forward name="success" path="/pages/Accounts.jsp"
>>redirect="false"/>
>> </action>
>>
>><action
>> path="/DispatchAction"
>> type="com.DispatchAction"
>> name="Form1"
>> scope="session"
>> parameter="method">
>> <forward name="successCalc" path="/PrepareAction.do"
>>redirect="false"/>
>> </action>
>>
>>
>>In the jsp have a submit button which dispatches to the dispatch action to
>>one of the methods in it.
>>I am setting one of the form property value in that method.
>>
>>
>>public class DispatchAction extends LookupDispatchAction {
>>
>> protected Map getKeyMethodMap() {
>> Map map = new HashMap();
>> map.put("btn.calc", "calc");
>> }
>>
>> public ActionForward calculate(ActionMapping mapping,
>> ActionForm form,
>> HttpServletRequest request,
>> HttpServletResponse response)
>> throws IOException, ServletException {
>> DynaValidatorForm frm = (DynaValidatorForm)form;
>>
>> frm.set("typeName", "xxxxx");
>>
>> return mapping.findForward("successCalc");
>> }
>>
>> }
>>
>>
>>setting the form-property value in the dispatch action i.e the "typeName"
>>to
>>"xxxxx"
>>
>>When it is sucess it is going back to the prepare action and the form
>>property value is "" instead of "xxxxx". checked at the first statement in
>>the execute method in prepare action the form-property value is different.
>>
>>not sure why the form-property value is different in prepare action as
>>before. When in dispatch action the form-bean had the right value i.e the
>>form-property in form-bean to "xxxxx". but when came to prepare it's value
>>is lost.
>>
>>why is this happenning? how can this be fixed?
>>
>>Thanks.
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>For additional commands, e-mail: user-help@struts.apache.org
>
_________________________________________________________________
Add fun gadgets and colorful themes to express yourself on Windows Live
Spaces
http://clk.atdmt.com/MSN/go/msnnkwsp0070000001msn/direct/01/?href=http://www.get.live.com/spaces/features
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: form-property value set in dispatch action is lost
Posted by Michael Jouravlev <jm...@gmail.com>.
You use the same form in both actions, and you chain them without a
redirect, so the request parameters are applied to your form again
when you forward to PrepareAction.
Struts repopulates your form with request parameters, so if the
parameter is mentioned in the request and it is emply, Struts will
clear the value you've set.
Also check your reset() method, Struts will call it before populating
the form. This method is called from both of your actions, and you
should not clear your form if PrepareAction is called.
On 9/19/06, fea jabi <zy...@hotmail.com> wrote:
> In struts config have a Dynavalidator form-bean
>
> <form-bean name="Form1" type=".... DynaValidatorForm">
> <form-property name="typeName" type="java.lang.String"/>
> ......
> </form-bean>
>
> have prepare(Action) and dispath(LookupDispatchAction) actions for the jsp
> in the config which are session scoped.
>
> <action
> path="/PrepareAction"
> type="com.PrepareAction"
> name="Form1"
> scope="session">
> <forward name="success" path="/pages/Accounts.jsp"
> redirect="false"/>
> </action>
>
> <action
> path="/DispatchAction"
> type="com.DispatchAction"
> name="Form1"
> scope="session"
> parameter="method">
> <forward name="successCalc" path="/PrepareAction.do"
> redirect="false"/>
> </action>
>
>
> In the jsp have a submit button which dispatches to the dispatch action to
> one of the methods in it.
> I am setting one of the form property value in that method.
>
>
> public class DispatchAction extends LookupDispatchAction {
>
> protected Map getKeyMethodMap() {
> Map map = new HashMap();
> map.put("btn.calc", "calc");
> }
>
> public ActionForward calculate(ActionMapping mapping,
> ActionForm form,
> HttpServletRequest request,
> HttpServletResponse response)
> throws IOException, ServletException {
> DynaValidatorForm frm = (DynaValidatorForm)form;
>
> frm.set("typeName", "xxxxx");
>
> return mapping.findForward("successCalc");
> }
>
> }
>
>
> setting the form-property value in the dispatch action i.e the "typeName" to
> "xxxxx"
>
> When it is sucess it is going back to the prepare action and the form
> property value is "" instead of "xxxxx". checked at the first statement in
> the execute method in prepare action the form-property value is different.
>
> not sure why the form-property value is different in prepare action as
> before. When in dispatch action the form-bean had the right value i.e the
> form-property in form-bean to "xxxxx". but when came to prepare it's value
> is lost.
>
> why is this happenning? how can this be fixed?
>
> Thanks.
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: form-property value set in dispatch action is lost
Posted by fea jabi <zy...@hotmail.com>.
sorry, it was a typo. I have a rigt method 'calc' itself.
>From: "Wendy Smoak" <ws...@gmail.com>
>Reply-To: "Struts Users Mailing List" <us...@struts.apache.org>
>To: "Struts Users Mailing List" <us...@struts.apache.org>
>Subject: Re: form-property value set in dispatch action is lost
>Date: Tue, 19 Sep 2006 13:23:36 -0700
>
>On 9/19/06, fea jabi <zy...@hotmail.com> wrote:
>
>>public class DispatchAction extends LookupDispatchAction {
>
>That's confusing... Struts already has a DispatchAction.
>
>> protected Map getKeyMethodMap() {
>> Map map = new HashMap();
>> map.put("btn.calc", "calc");
>> }
>>
>> public ActionForward calculate(ActionMapping mapping,
>
>This doesn't match. getKeyMethodMap should map property keys to method
>names.
>
>http://struts.apache.org/1.x/struts-extras/apidocs/org/apache/struts/actions/LookupDispatchAction.html
>
>Do you have another method called 'calc'?
>
>It's not clear that the 'calculate' method is even executing.
>
>--
>Wendy
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>For additional commands, e-mail: user-help@struts.apache.org
>
_________________________________________________________________
Get today's hot entertainment gossip http://movies.msn.com/movies/hotgossip
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: form-property value set in dispatch action is lost
Posted by fea jabi <zy...@hotmail.com>.
sorry, it was a typo. I have a rigt method 'calc' itself.
>From: "Wendy Smoak" <ws...@gmail.com>
>Reply-To: "Struts Users Mailing List" <us...@struts.apache.org>
>To: "Struts Users Mailing List" <us...@struts.apache.org>
>Subject: Re: form-property value set in dispatch action is lost
>Date: Tue, 19 Sep 2006 13:23:36 -0700
>
>On 9/19/06, fea jabi <zy...@hotmail.com> wrote:
>
>>public class DispatchAction extends LookupDispatchAction {
>
>That's confusing... Struts already has a DispatchAction.
>
>> protected Map getKeyMethodMap() {
>> Map map = new HashMap();
>> map.put("btn.calc", "calc");
>> }
>>
>> public ActionForward calculate(ActionMapping mapping,
>
>This doesn't match. getKeyMethodMap should map property keys to method
>names.
>
>http://struts.apache.org/1.x/struts-extras/apidocs/org/apache/struts/actions/LookupDispatchAction.html
>
>Do you have another method called 'calc'?
>
>It's not clear that the 'calculate' method is even executing.
>
>--
>Wendy
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>For additional commands, e-mail: user-help@struts.apache.org
>
_________________________________________________________________
Add fun gadgets and colorful themes to express yourself on Windows Live
Spaces
http://clk.atdmt.com/MSN/go/msnnkwsp0070000001msn/direct/01/?href=http://www.get.live.com/spaces/features
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: form-property value set in dispatch action is lost
Posted by Wendy Smoak <ws...@gmail.com>.
On 9/19/06, fea jabi <zy...@hotmail.com> wrote:
> public class DispatchAction extends LookupDispatchAction {
That's confusing... Struts already has a DispatchAction.
> protected Map getKeyMethodMap() {
> Map map = new HashMap();
> map.put("btn.calc", "calc");
> }
>
> public ActionForward calculate(ActionMapping mapping,
This doesn't match. getKeyMethodMap should map property keys to method names.
http://struts.apache.org/1.x/struts-extras/apidocs/org/apache/struts/actions/LookupDispatchAction.html
Do you have another method called 'calc'?
It's not clear that the 'calculate' method is even executing.
--
Wendy
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
RE: form-property value set in dispatch action is lost
Posted by fea jabi <zy...@hotmail.com>.
I do have the dynamic="true" set too.
><form-bean name="Form1" type=".... DynaValidatorForm" dynamic="true">
> <form-property name="typeName" type="java.lang.String"/>
>......
></form-bean>
>From: "fea jabi" <zy...@hotmail.com>
>Reply-To: "Struts Users Mailing List" <us...@struts.apache.org>
>To: user@struts.apache.org
>Subject: form-property value set in dispatch action is lost
>Date: Tue, 19 Sep 2006 15:43:37 -0400
>
>In struts config have a Dynavalidator form-bean
>
><form-bean name="Form1" type=".... DynaValidatorForm">
> <form-property name="typeName" type="java.lang.String"/>
>......
></form-bean>
>
>have prepare(Action) and dispath(LookupDispatchAction) actions for the jsp
>in the config which are session scoped.
>
><action
> path="/PrepareAction"
> type="com.PrepareAction"
> name="Form1"
> scope="session">
> <forward name="success" path="/pages/Accounts.jsp"
>redirect="false"/>
> </action>
>
><action
> path="/DispatchAction"
> type="com.DispatchAction"
> name="Form1"
> scope="session"
> parameter="method">
> <forward name="successCalc" path="/PrepareAction.do"
>redirect="false"/>
> </action>
>
>
>In the jsp have a submit button which dispatches to the dispatch action to
>one of the methods in it.
>I am setting one of the form property value in that method.
>
>
>public class DispatchAction extends LookupDispatchAction {
>
> protected Map getKeyMethodMap() {
> Map map = new HashMap();
> map.put("btn.calc", "calc");
> }
>
> public ActionForward calculate(ActionMapping mapping,
> ActionForm form,
> HttpServletRequest request,
> HttpServletResponse response)
> throws IOException, ServletException {
> DynaValidatorForm frm = (DynaValidatorForm)form;
>
> frm.set("typeName", "xxxxx");
>
> return mapping.findForward("successCalc");
> }
>
> }
>
>
>setting the form-property value in the dispatch action i.e the "typeName"
>to "xxxxx"
>
>When it is sucess it is going back to the prepare action and the form
>property value is "" instead of "xxxxx". checked at the first statement in
>the execute method in prepare action the form-property value is different.
>
>not sure why the form-property value is different in prepare action as
>before. When in dispatch action the form-bean had the right value i.e the
>form-property in form-bean to "xxxxx". but when came to prepare it's value
>is lost.
>
>why is this happenning? how can this be fixed?
>
>Thanks.
>
>_________________________________________________________________
>Express yourself - download free Windows Live Messenger themes!
>http://clk.atdmt.com/MSN/go/msnnkwme0020000001msn/direct/01/?href=http://imagine-msn.com/themes/vibe/default.aspx?locale=en-us&source=hmtagline
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>For additional commands, e-mail: user-help@struts.apache.org
>
_________________________________________________________________
Search—Your way, your world, right now!
http://imagine-windowslive.com/minisites/searchlaunch/?locale=en-us&FORM=WLMTAG
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org