You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Vinh Tran <vi...@processintelligence.com> on 2003/02/03 14:49:02 UTC

Getting Request Parameters After validate()

All:

I am having problems retrieving request values after submitting a form that
goes through validate().  Below is an example.  Please help!

In the example below I have an action that shows the form using MyEditAction
with no validation (request values work fine). After submitting the form
ensuring a value that will cause an error I am sent back to the testform.jsp
as expected. However, none of the request attributes are available even
though I have the necessary values in hidden form elements, such as the test
hidden property shown below.

struts-config:
<action
	path="/myEditFormAction"
	type="com.foo.bar.actions.MyEditAction"
	name="myEditForm"
	input="/testform.jsp"
	validate="false">
	<forward name="success" path="/success.jsp"/>
</action>

<action
	path="/myEditAction"
	type="com.foo.bar.actions.MyEditAction"
	name="myEditForm"
	input="/testform.jsp"
	validate="true">
	<forward name="success" path="/success.jsp"/>
</action>

testform.jsp:
<html:form action="/publisher/editTextEntity">
<html:hidden property="test" value="testValue"/>
...
</html:form>


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


Re: Getting Request Parameters After validate()

Posted by Nicolas De Loof <ni...@cgey.com>.
IMHO request scope should be used to put volatile datas, such as error
messages or computation result. A JSP that uses validation should be able to
display back without "preprocessing", I mean needed datas should be present
as properties of the formbean (or other session scoped bean).

Using validate() to put datas back into request scope is not a nice way to
ensure JSP is able to display. But I don't know your project constraints, so
it could be a solution. I just recommend not mixing session/request scopes
handling and validation
code, as validate() allow you to concentrate controls into one method. This
way you would be able to use declarative validation when you migrate to
Struts 1.1.

Nico.

> Thanks for clearing that up Nico.  That makes complete sense.  I did
notice
> that Request is available in the validate() method in which case I should
be
> able to set my request parameters within validate().  Do you know if this
is
> NOT a good way to forward request attributes if validation errors occur?
>


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


RE: Getting Request Parameters After validate()

Posted by Vinh Tran <vi...@processintelligence.com>.
Thanks for clearing that up Nico.  That makes complete sense.  I did notice
that Request is available in the validate() method in which case I should be
able to set my request parameters within validate().  Do you know if this is
NOT a good way to forward request attributes if validation errors occur?

-----Original Message-----
From: Nicolas De Loof [mailto:nicolas.deloof@cgey.com]
Sent: Monday, February 03, 2003 9:35 AM
To: Struts Users Mailing List; vinht@processintelligence.com
Subject: Re: Getting Request Parameters After validate()


As you are using validation, your action will not execute since they're
validation errors. "input" will be called back with request scoped errors.
"MyEditAction" will be called only if no validation error occurs. So you
will not have any data in request scope (only errors setted by validation
process).
If your JSP needs some datas to display back, they should be beans in
application/session scope or properties of the formbean.

Nico.

> Hmm....I was under the impression that a submit went through the action
> class specified in the type attribute which simply uses my form bean. From
> my example below that would be com.foo.bar.actions.MyEditAction. In which
> case my "test" attribute should be availble in MyEditAction.
>
> <action
> path="/myEditAction"
> type="com.foo.bar.actions.MyEditAction"
> name="myEditForm"
> input="/testform.jsp"
> validate="true">
> <forward name="success" path="/success.jsp"/>
> </action>
>
> Am I completely off and stand corrected?
>
> Vinh
>
> -----Original Message-----
> From: Nicolas De Loof [mailto:nicolas.deloof@cgey.com]
> Sent: Monday, February 03, 2003 8:54 AM
> To: Struts Users Mailing List; vinht@processintelligence.com
> Subject: Re: Getting Request Parameters After validate()
>
>
> When validation send you back your request scope is empty as you have
> submited a new request ! Your "test" attribute will be present in your
> formbean, because formbean population has occured. For beeing able to
> display back your JSP you will have to use session scope beans or use
> formbean attributes.
>
> Nico.
>
>
> > All:
> >
> > I am having problems retrieving request values after submitting a form
> that
> > goes through validate().  Below is an example.  Please help!
> >
> > In the example below I have an action that shows the form using
> MyEditAction
> > with no validation (request values work fine). After submitting the form
> > ensuring a value that will cause an error I am sent back to the
> testform.jsp
> > as expected. However, none of the request attributes are available even
> > though I have the necessary values in hidden form elements, such as the
> test
> > hidden property shown below.
> >
> > struts-config:
> > <action
> > path="/myEditFormAction"
> > type="com.foo.bar.actions.MyEditAction"
> > name="myEditForm"
> > input="/testform.jsp"
> > validate="false">
> > <forward name="success" path="/success.jsp"/>
> > </action>
> >
> > <action
> > path="/myEditAction"
> > type="com.foo.bar.actions.MyEditAction"
> > name="myEditForm"
> > input="/testform.jsp"
> > validate="true">
> > <forward name="success" path="/success.jsp"/>
> > </action>
> >
> > testform.jsp:
> > <html:form action="/publisher/editTextEntity">
> > <html:hidden property="test" value="testValue"/>
> > ...
> > </html:form>
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: struts-user-help@jakarta.apache.org
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: struts-user-help@jakarta.apache.org



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


Re: Getting Request Parameters After validate()

Posted by Nicolas De Loof <ni...@cgey.com>.
As you are using validation, your action will not execute since they're
validation errors. "input" will be called back with request scoped errors.
"MyEditAction" will be called only if no validation error occurs. So you
will not have any data in request scope (only errors setted by validation
process).
If your JSP needs some datas to display back, they should be beans in
application/session scope or properties of the formbean.

Nico.

> Hmm....I was under the impression that a submit went through the action
> class specified in the type attribute which simply uses my form bean. From
> my example below that would be com.foo.bar.actions.MyEditAction. In which
> case my "test" attribute should be availble in MyEditAction.
>
> <action
> path="/myEditAction"
> type="com.foo.bar.actions.MyEditAction"
> name="myEditForm"
> input="/testform.jsp"
> validate="true">
> <forward name="success" path="/success.jsp"/>
> </action>
>
> Am I completely off and stand corrected?
>
> Vinh
>
> -----Original Message-----
> From: Nicolas De Loof [mailto:nicolas.deloof@cgey.com]
> Sent: Monday, February 03, 2003 8:54 AM
> To: Struts Users Mailing List; vinht@processintelligence.com
> Subject: Re: Getting Request Parameters After validate()
>
>
> When validation send you back your request scope is empty as you have
> submited a new request ! Your "test" attribute will be present in your
> formbean, because formbean population has occured. For beeing able to
> display back your JSP you will have to use session scope beans or use
> formbean attributes.
>
> Nico.
>
>
> > All:
> >
> > I am having problems retrieving request values after submitting a form
> that
> > goes through validate().  Below is an example.  Please help!
> >
> > In the example below I have an action that shows the form using
> MyEditAction
> > with no validation (request values work fine). After submitting the form
> > ensuring a value that will cause an error I am sent back to the
> testform.jsp
> > as expected. However, none of the request attributes are available even
> > though I have the necessary values in hidden form elements, such as the
> test
> > hidden property shown below.
> >
> > struts-config:
> > <action
> > path="/myEditFormAction"
> > type="com.foo.bar.actions.MyEditAction"
> > name="myEditForm"
> > input="/testform.jsp"
> > validate="false">
> > <forward name="success" path="/success.jsp"/>
> > </action>
> >
> > <action
> > path="/myEditAction"
> > type="com.foo.bar.actions.MyEditAction"
> > name="myEditForm"
> > input="/testform.jsp"
> > validate="true">
> > <forward name="success" path="/success.jsp"/>
> > </action>
> >
> > testform.jsp:
> > <html:form action="/publisher/editTextEntity">
> > <html:hidden property="test" value="testValue"/>
> > ...
> > </html:form>
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: struts-user-help@jakarta.apache.org
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: struts-user-help@jakarta.apache.org


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


RE: Getting Request Parameters After validate()

Posted by Vinh Tran <vi...@processintelligence.com>.
Hmm....I was under the impression that a submit went through the action
class specified in the type attribute which simply uses my form bean. From
my example below that would be com.foo.bar.actions.MyEditAction. In which
case my "test" attribute should be availble in MyEditAction.

<action
	path="/myEditAction"
	type="com.foo.bar.actions.MyEditAction"
	name="myEditForm"
	input="/testform.jsp"
	validate="true">
	<forward name="success" path="/success.jsp"/>
</action>

Am I completely off and stand corrected?

Vinh

-----Original Message-----
From: Nicolas De Loof [mailto:nicolas.deloof@cgey.com]
Sent: Monday, February 03, 2003 8:54 AM
To: Struts Users Mailing List; vinht@processintelligence.com
Subject: Re: Getting Request Parameters After validate()


When validation send you back your request scope is empty as you have
submited a new request ! Your "test" attribute will be present in your
formbean, because formbean population has occured. For beeing able to
display back your JSP you will have to use session scope beans or use
formbean attributes.

Nico.


> All:
>
> I am having problems retrieving request values after submitting a form
that
> goes through validate().  Below is an example.  Please help!
>
> In the example below I have an action that shows the form using
MyEditAction
> with no validation (request values work fine). After submitting the form
> ensuring a value that will cause an error I am sent back to the
testform.jsp
> as expected. However, none of the request attributes are available even
> though I have the necessary values in hidden form elements, such as the
test
> hidden property shown below.
>
> struts-config:
> <action
> path="/myEditFormAction"
> type="com.foo.bar.actions.MyEditAction"
> name="myEditForm"
> input="/testform.jsp"
> validate="false">
> <forward name="success" path="/success.jsp"/>
> </action>
>
> <action
> path="/myEditAction"
> type="com.foo.bar.actions.MyEditAction"
> name="myEditForm"
> input="/testform.jsp"
> validate="true">
> <forward name="success" path="/success.jsp"/>
> </action>
>
> testform.jsp:
> <html:form action="/publisher/editTextEntity">
> <html:hidden property="test" value="testValue"/>
> ...
> </html:form>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: struts-user-help@jakarta.apache.org



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


Re: Getting Request Parameters After validate()

Posted by Nicolas De Loof <ni...@cgey.com>.
When validation send you back your request scope is empty as you have
submited a new request ! Your "test" attribute will be present in your
formbean, because formbean population has occured. For beeing able to
display back your JSP you will have to use session scope beans or use
formbean attributes.

Nico.


> All:
>
> I am having problems retrieving request values after submitting a form
that
> goes through validate().  Below is an example.  Please help!
>
> In the example below I have an action that shows the form using
MyEditAction
> with no validation (request values work fine). After submitting the form
> ensuring a value that will cause an error I am sent back to the
testform.jsp
> as expected. However, none of the request attributes are available even
> though I have the necessary values in hidden form elements, such as the
test
> hidden property shown below.
>
> struts-config:
> <action
> path="/myEditFormAction"
> type="com.foo.bar.actions.MyEditAction"
> name="myEditForm"
> input="/testform.jsp"
> validate="false">
> <forward name="success" path="/success.jsp"/>
> </action>
>
> <action
> path="/myEditAction"
> type="com.foo.bar.actions.MyEditAction"
> name="myEditForm"
> input="/testform.jsp"
> validate="true">
> <forward name="success" path="/success.jsp"/>
> </action>
>
> testform.jsp:
> <html:form action="/publisher/editTextEntity">
> <html:hidden property="test" value="testValue"/>
> ...
> </html:form>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: struts-user-help@jakarta.apache.org


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