struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Christopher Schultz <ch...@christopherschultz.net>
Subject Re: Multiple buttons and validation
Date Tue, 12 Dec 2006 17:36:12 GMT
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Thom,

Thom Burnett wrote:
> I have a few buttons on my jsp page and I want to have validation happen on
> some buttons and not on other buttons.
> 
> Is that possible? How? Any examples around?

This question came up a few weeks ago, and I'll tell you what I told
whoever asked in the past. There may be other solutions, but this one is
fairly straightforward.

First, you create an action that is intended to handle the form
submission itself. No need for a form bean or anything like that (and,
of course, there's no validation). Just write it like this:

public ActionMapping execute(...)
{
    if(null != request.getParameter("first_button"))
       return mapping.findForward("first-forward");
    else if(null != request.getParameter("second_button"))
       return mapping.findForward("second-forward");
    else if(null != request.getParameter("third_button"))
       return mapping.findForward("third-forward");
    .
    .
    .
}

Then, your first-, second-, and third-forwards can be defined to forward
(not redirect) the request to the "real" actions that do whatever you
want them to do. /Those/ actions should have form bean associated with
them and validation="true" in the mappings.

Remember that your "real" actions should all have the same "input" set
so that any validation errors will go back to the same page.

Hope that helps,
- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFFfuiL9CaO5/Lv0PARAir4AKDCPozKfHQnaYXOzB+82nlmPmJuGQCeKQpH
C8fLHrm2tqDo2N/EKF+sbBA=
=6HwP
-----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