You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by "Phan, Hienthuc T" <hi...@merck.com> on 2008/05/17 03:40:50 UTC

Struts 2: After validation fail, how to change the returning result name to other than INPUT?

Hi,

I have a CustomerAction class.  In CustomerAction, I have two methods:
add and update.  I have a CustomerAction-validation.xml to check for
required fields, etc.  My struts.xml looks something like this:

	<package name="customer">
		<action name="customer_*"
class="com.action.CustomerAction" method="{1}">
			<result
name="create">/customer_create.jsp</result>
			<result
name="update">/customer_update.jsp</result>
		</action>
	</package>

When the validation fail, I would like it to return to the previous page
(either cusomer_create.jsp or customer_update.jsp).  However, Struts
returns result = "input" automatically when the validation fail. How do
I change the result from "input" to either "add" or "update"?

A clunky way to solve this problem is to create two actions.  That would
generate too many classes.  Is there a good solution for this problem of
mine?  Thanks.

-Hien
Notice:  This e-mail message, together with any attachments, contains information of Merck & Co., Inc. (One Merck Drive, Whitehouse Station, New Jersey, USA 08889), and/or its affiliates (which may be known outside the United States as Merck Frosst, Merck Sharp & Dohme or MSD and in Japan, as Banyu - direct contact information for affiliates is available at http://www.merck.com/contact/contacts.html) that may be confidential, proprietary copyrighted and/or legally privileged. It is intended solely for the use of the individual or entity named on this message. If you are not the intended recipient, and have received this message in error, please notify us immediately by reply e-mail and then delete it from your system.

RE: Struts 2: After validation fail, how to change the returning result name to other than INPUT?

Posted by "Phan, Hienthuc T" <hi...@merck.com>.
Any suggestions???? 

-----Original Message-----
From: Phan, Hienthuc T 
Sent: Friday, May 16, 2008 6:41 PM
To: Struts Users Mailing List
Subject: Struts 2: After validation fail, how to change the returning
result name to other than INPUT?

Hi,

I have a CustomerAction class.  In CustomerAction, I have two methods:
add and update.  I have a CustomerAction-validation.xml to check for
required fields, etc.  My struts.xml looks something like this:

	<package name="customer">
		<action name="customer_*"
class="com.action.CustomerAction" method="{1}">
			<result
name="create">/customer_create.jsp</result>
			<result
name="update">/customer_update.jsp</result>
		</action>
	</package>

When the validation fail, I would like it to return to the previous page
(either cusomer_create.jsp or customer_update.jsp).  However, Struts
returns result = "input" automatically when the validation fail. How do
I change the result from "input" to either "add" or "update"?

A clunky way to solve this problem is to create two actions.  That would
generate too many classes.  Is there a good solution for this problem of
mine?  Thanks.

-Hien
Notice:  This e-mail message, together with any attachments, contains information of Merck & Co., Inc. (One Merck Drive, Whitehouse Station, New Jersey, USA 08889), and/or its affiliates (which may be known outside the United States as Merck Frosst, Merck Sharp & Dohme or MSD and in Japan, as Banyu - direct contact information for affiliates is available at http://www.merck.com/contact/contacts.html) that may be confidential, proprietary copyrighted and/or legally privileged. It is intended solely for the use of the individual or entity named on this message. If you are not the intended recipient, and have received this message in error, please notify us immediately by reply e-mail and then delete it from your system.


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


RE: Re: Struts 2: After validation fail, how to change the returning result name to other than INPUT?

Posted by "Phan, Hienthuc T" <hi...@merck.com>.
Laurie,

Thank you.  Your suggestion works great.  Very elegant!

-Hien

-----Original Message-----
From: news [mailto:news@ger.gmane.org] On Behalf Of Laurie Harper
Sent: Tuesday, May 20, 2008 1:55 PM
To: user@struts.apache.org
Subject: Re: Struts 2: After validation fail, how to change the
returning result name to other than INPUT?

Phan, Hienthuc T wrote:
> Hi,
> 
> I have a CustomerAction class.  In CustomerAction, I have two methods:
> add and update.  I have a CustomerAction-validation.xml to check for
> required fields, etc.  My struts.xml looks something like this:
> 
> 	<package name="customer">
> 		<action name="customer_*"
> class="com.action.CustomerAction" method="{1}">
> 			<result
> name="create">/customer_create.jsp</result>
> 			<result
> name="update">/customer_update.jsp</result>
> 		</action>
> 	</package>
> 
> When the validation fail, I would like it to return to the previous
page
> (either cusomer_create.jsp or customer_update.jsp).  However, Struts
> returns result = "input" automatically when the validation fail. How
do
> I change the result from "input" to either "add" or "update"?
> 
> A clunky way to solve this problem is to create two actions.  That
would
> generate too many classes.  Is there a good solution for this problem
of
> mine?  Thanks.

How do you know which one to return to? There are a few possibilities, 
but if the result name is the same as the method name you could do 
something like

   <action name="customer_*" method="{1}" ...>
     <result name="input">/customer_{1}.jsp"/>
     <result name="{1}">/customer_{1}.jsp"/>
   </action>

(note that I also collapsed your other two results using the same 
technique).

L.


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

Notice:  This e-mail message, together with any attachments, contains information of Merck & Co., Inc. (One Merck Drive, Whitehouse Station, New Jersey, USA 08889), and/or its affiliates (which may be known outside the United States as Merck Frosst, Merck Sharp & Dohme or MSD and in Japan, as Banyu - direct contact information for affiliates is available at http://www.merck.com/contact/contacts.html) that may be confidential, proprietary copyrighted and/or legally privileged. It is intended solely for the use of the individual or entity named on this message. If you are not the intended recipient, and have received this message in error, please notify us immediately by reply e-mail and then delete it from your system.


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


Re: Struts 2: After validation fail, how to change the returning result name to other than INPUT?

Posted by Laurie Harper <la...@holoweb.net>.
Phan, Hienthuc T wrote:
> Hi,
> 
> I have a CustomerAction class.  In CustomerAction, I have two methods:
> add and update.  I have a CustomerAction-validation.xml to check for
> required fields, etc.  My struts.xml looks something like this:
> 
> 	<package name="customer">
> 		<action name="customer_*"
> class="com.action.CustomerAction" method="{1}">
> 			<result
> name="create">/customer_create.jsp</result>
> 			<result
> name="update">/customer_update.jsp</result>
> 		</action>
> 	</package>
> 
> When the validation fail, I would like it to return to the previous page
> (either cusomer_create.jsp or customer_update.jsp).  However, Struts
> returns result = "input" automatically when the validation fail. How do
> I change the result from "input" to either "add" or "update"?
> 
> A clunky way to solve this problem is to create two actions.  That would
> generate too many classes.  Is there a good solution for this problem of
> mine?  Thanks.

How do you know which one to return to? There are a few possibilities, 
but if the result name is the same as the method name you could do 
something like

   <action name="customer_*" method="{1}" ...>
     <result name="input">/customer_{1}.jsp"/>
     <result name="{1}">/customer_{1}.jsp"/>
   </action>

(note that I also collapsed your other two results using the same 
technique).

L.


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