wood burning stoves 2.0*
The moose likes Struts and the fly likes Buttons in Struts Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Buttons in Struts" Watch "Buttons in Struts" New topic
Author

Buttons in Struts

Charles McGuire
Ranch Hand

Joined: Jan 18, 2005
Posts: 99
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?

I'm not using any JavaScript, so no client side validations to worry about.

BTW - I got my first Struts app to work. I'm buying tonight!


There's no place like 127.0.0.1
Charles McGuire
Ranch Hand

Joined: Jan 18, 2005
Posts: 99
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.
Marc Peabody
pie sneak
Sheriff

Joined: Feb 05, 2003
Posts: 4727

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.


A good workman is known by his tools.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Buttons in Struts