struts-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Craig R. McClanahan" <craig...@apache.org>
Subject Re: Handling multiple button actions in struts html form
Date Tue, 13 Mar 2001 20:05:18 GMT


On Tue, 13 Mar 2001, Open Source wrote:

> Hi,
> 
> I have started developing some real life jsp
> applications with Struts now.
> I have a rather simple question which might have
> addresed in Struts , but I could not figure it out.
> 
> I have two questions 
> 1.  When a html form (using struts) has 2 buttons -
> Submit and Cancel(<html:cancel>. Submit will validate
> the form before going any further.
> Cancel button however bypasses the validation and goes
> straight to perfom method in the Action.
> Actually I just want to go to a page cancel.jsp on
> pressng cancel button.
> What is the right way to do it ?

After the validation step is skipped, your Action's perform() method is
still called.  You could add the following logic at the beginning:

	if (isCancelled(request))
	    return (mapping.findForward("Cancelled"));

which will look up the appropriate <forward> declaration that you have set
up, to tell the system which page to display.


> I can think of only one way - In perform method, check
> if  req.getParameter(Constants.CANCEL_PROPERTY) ==
> "cancel" and then findforward("cancelpage")
> where cancelpage is mapped as a global forward to
> cancel.jsp
> Is there any better way, please advise.
> 

The Action class includes a convenience method that basically does this
check for you.

> 2.  When there are multiple buttons(4 to 5) in a form
> what is the generic procedure adopted ?
> esp when 
> button B1 should check for something and then go to
> Page A or Page B
> Button B2 always takes me to PageC
> etc...
> Is it still the same req.getParameter() advised here
> 

That's what I would do.

One thing you have to watch out for is that the text being submitted for
the button name is the same as that displayed on the screen, and might
have been internationalized.


> I appreciate any and all of your suggestions.
> 
> Thanks a lot,
> Srikanth
> 

Craig McClanahan


Mime
View raw message