You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by "Zhang, Larry (L.)" <lz...@ford.com> on 2008/01/25 18:08:02 UTC

Can I use one action for displaying and submission (with struts validation)

 
I was noticing an issue if I use one action for both displaying and
submission purposes:

Say MyAction.java is for displaying page and also for submission. If on
the page there is text field needing the struts validator validation,
then if failing validation, I forward to MyAction.java and comes to the
validation again, and fail again and forward to the MyAction again. This
is an infinite loop, any suggestions to overcome this and still use one
action? Or we have to use two actions(one display and one for
submission) the serve the purposes.

Thanks in advance.

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


Re: Can I use one action for displaying and submission (with struts validation)

Posted by Laurie Harper <la...@holoweb.net>.
Paul Benedict wrote:
> You can use this pattern:
> 
> * Turn automatic validation off.
> 
> * If your action was executed as a GET, branch to viewing logic.
> 
> * If your action was executed as a POST, branch to validation logic and
> submission logic.

Another approach is to retain declarative validation and a single 
action, but use two action mappings. Both mappings point to the same 
action class, one has validation turned off and handles form display 
while the other has validation turned on and handles the submit.

You presumably already have some mechanism to distinguish form request 
from form submit, so you can apply Paul's solution substituting that 
mechanism for the GET vs. POST test.

L.


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


RE: Can I use one action for displaying and submission (with struts validation)

Posted by Dave Newton <ne...@yahoo.com>.
--- "Zhang, Larry (L.)" <lz...@ford.com> wrote:
> I am intested in knowing how to turn automatic validation off? How?

Automagic validation is controlled by the "validate" attribute in the
struts-config files.

> Also all my submission is also get (for some reasons in our project) 

That'll make it harder; is there any particular reason you can't just change
form submissions to POST? 

It certainly follows the spirit of HTTP a bit more closely and makes Msgr.
Benedictus' logic trivial to implement.

d.

> -----Original Message-----
> From: paulus.benedictus@gmail.com [mailto:paulus.benedictus@gmail.com]
> On Behalf Of Paul Benedict
> Sent: Friday, January 25, 2008 12:15 PM
> To: Struts Users Mailing List
> Subject: Re: Can I use one action for displaying and submission (with
> struts validation)
> 
> You can use this pattern:
> 
> * Turn automatic validation off.
> 
> * If your action was executed as a GET, branch to viewing logic.
> 
> * If your action was executed as a POST, branch to validation logic and
> submission logic.
> 
> Paul
> 
> ---------------------------------------------------------------------
> 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


RE: Can I use one action for displaying and submission (with struts validation)

Posted by "Zhang, Larry (L.)" <lz...@ford.com>.
I am intested in knowing how to turn automatic validation off? How?
Using javascript to set the flag is not accepted by us.

Also all my submission is also get (for some reasons in our project) 

-----Original Message-----
From: paulus.benedictus@gmail.com [mailto:paulus.benedictus@gmail.com]
On Behalf Of Paul Benedict
Sent: Friday, January 25, 2008 12:15 PM
To: Struts Users Mailing List
Subject: Re: Can I use one action for displaying and submission (with
struts validation)

You can use this pattern:

* Turn automatic validation off.

* If your action was executed as a GET, branch to viewing logic.

* If your action was executed as a POST, branch to validation logic and
submission logic.

Paul

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


Re: Can I use one action for displaying and submission (with struts validation)

Posted by Paul Benedict <pb...@apache.org>.
You can use this pattern:

* Turn automatic validation off.

* If your action was executed as a GET, branch to viewing logic.

* If your action was executed as a POST, branch to validation logic and
submission logic.

Paul