Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Buttons in Struts

 
Charles McGuire
Ranch Hand
Posts: 99
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!
 
Charles McGuire
Ranch Hand
Posts: 99
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4727
Mac Ruby VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic