struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Christopher Schultz <>
Subject Re: Validation + multiple Submit buttons
Date Tue, 14 Nov 2006 14:36:32 GMT
Hash: SHA1


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="..../" />
<forward name="back" path="..../" />

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

Version: GnuPG v1.4.5 (MingW32)
Comment: Using GnuPG with Mozilla -


To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message