struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Christopher Schultz <ch...@christopherschultz.net>
Subject Re: Validation + multiple Submit buttons
Date Tue, 14 Nov 2006 14:36:32 GMT
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Andrew,

Andrew Martin wrote:
> That would be one solution, but in my case I have 4 submit buttons,
> two of which redirect the user to another action (keeping scope set to session)
> and then back to the original form.

Hmm... that makes things more interesting.

How about this:

You create a new action called "figureItOutAction" or something like
that, and POST your form to that action. This action has no form bean,
no validation, no nuthin'.

In that action, you look for the names of the buttons that you want to
use, say: SAVE, BACK, CANCEL, and FOURTH_BUTTON (or whatever). Then, you
dispatch based upon the button that was pressed:

in struts-config.xml:
<forward name="save" path="..../save.do" />
<forward name="back" path="..../back.do" />
.
.
.

Remember to definitely NOT set redirect="true", since we need the reques
to stay in tact.

Your code for FigureItOutAction will look like this:

if(null != request.getParameter("save"))
   return mapping.findForward("save");
else if(null != request.getParameter("back"))
   return mapping.findForward("back");
.
.
.

Then, just point each of these dispatching actions to the ones that
really do the work. Each of these may have validation, form beans, etc.
For instance, your "save" action (or "next"... whatever) will have a
form bean and validate="true" in struts-config.xml.

This trick allows you to submit your form to an action which decides
what to do independently of validation. Forwarding on to another action
that /does/ validate will then give you the magic of validation.

I haven't tried this before, but it should work.

- -chris

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.5 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFFWdRw9CaO5/Lv0PARAra+AJ9zZ4ejuncDFJXlQHicNXykEh9EWACgqTBJ
GTAT1awgUG4RugUt/9jQNmw=
=jcpP
-----END PGP SIGNATURE-----

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


Mime
View raw message