• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Buttons in Struts

 
Ranch Hand
Posts: 99
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
pie sneak
Posts: 4727
Mac VI Editor Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic