Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Struts Cancel Button submits the form

 
Aalok Mishra
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

i am using the struts tag lib in my code. I have created an image control to use instead of traditional buttons. The submit button works fine but the cancel button is not behaving proprly. It just submits the form instead of cancelling it when the cancel button is pressed. Can any one help me in this?

Here is my code:
Login.jsp


Struts-config.xml
 
Merrill Higginson
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you'll look closely at The Taglib documentation, you will see that an html:cancel button does cause a submit button to be rendered. The main difference is that it will bypass any validation. If your action class is a subclass of DispatchAction as yours appears to be, just code a cancelled method to handle the case where the cancel button is pressed. Also, don't forget to put cancellable="true" in the action path definition in your struts-config.xml file.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic