Can someone tell me how buttons work in struts, specifically a cancel button? I have the <html:cancel/> button on my jsp, but I don't know how to finish it. Surprisingly, my reference material doesn't have a lot in this area.
Is a property set on my ActionForm bean? Is a method automatically called on my Action class, such as isCancelled? Is this treated as an action-forward in my mappings?
BTW - I got my first Struts app to work. I'm buying tonight!
There's no place like 127.0.0.1
Joined: Jan 18, 2005
I just found out about the isCancelled method from the Action class that my action class is extending. Cancel works fine.
Now, what about other buttons? Thanks in advance... again.
Is a property set on my ActionForm bean? Only if there is a setter method to match it. View the source of your html when you get to your page. It will look something like: <input type="submit" name="submitName" value="Submit Me"> Clicking this button adds submitName=Submit Me to the list of request parameters. If the ActionForm has a setSubmitName method, it will affectively call setSubmitName("Submit Me").
When using the Struts button tags you can specify the property and value attributes. The property turns into name and the value stays as value when the tag is converted to html.
When using a button tag like html:cancel, Struts has default attribute values, so you don't have to specify anything.
Is a method automatically called on my Action class, such as isCancelled? No methods are automatically called. The isCancelled checks the request parameters for Strut's default html:cancel property (remember that I said Struts had a default one if you didn't specify it. I think validation might get skipped if you use html:cancel (with the default property) but it's hard to remember.
Is this treated as an action-forward in my mappings? Nope. It's just another name-value pair in the html form's request.