wood burning stoves 2.0*
The moose likes Struts and the fly likes Avoiding validation when hitting the Cancel button Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Avoiding validation when hitting the Cancel button" Watch "Avoiding validation when hitting the Cancel button" New topic
Author

Avoiding validation when hitting the Cancel button

Dan Waters
Greenhorn

Joined: May 07, 2004
Posts: 11
I have a DispatchAction and TestForm (extends ValidatorForm). I want to
avoid validation when the user clicks the Cancel button. Currently the
Cancel button is coded like this

<html:submit value="Cancel" property="command">

public class TestAction extends DispatchAction {

public ActionForward Cancel(ActionMapping mapping, ActionForm form, HttpRequest..) {
return mapping.findForward("mainpage");
}
}


When I click cancel, the Cancel method is not called.. because the Validation of the form takes place before hands and the form gets back to the view.
Jeanne Boyarsky
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 30789
    
157

Dan,
There is an html:cancel tag for this purpose. It bypasses the validation.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Dan Waters
Greenhorn

Joined: May 07, 2004
Posts: 11
Ok if I use

<html:cancel>. How do I identify the Cancel action in my Action class, because
I need to forward to a different screen when a Cancel button is pressed.
Jeanne Boyarsky
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 30789
    
157

Dan,
Just have your action call:
isCancelled(request)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Avoiding validation when hitting the Cancel button