File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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
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
internet detective
Marshal

Joined: May 26, 2003
Posts: 30123
    
150

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
internet detective
Marshal

Joined: May 26, 2003
Posts: 30123
    
150

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
 
Similar Threads
Newbie no validation on Cancel button click.
execute method
Cancel button and bypassing JavaScript validation
Bypass client-side struts validation
problem using validator framework with DispatchAction