• 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 EventHandler and Property-Setting

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello all,

I've got a question regarding struts and HTML-Buttons.

As soon as I connect an event-handler (for example onclick) with the button which causes a submission of the surrounding form, the button's property itself is not set.

So it seems that the browser first handles the event handlers of an HTML element before it sets the appropriate values into the fields of the appropriate element (for me: the button)!

Is there any way to get the value of the button when submitting the form with an event handler connected to the button?

Currently I'm sending the button's value as a request parameter attached to the URL the event handler calls (not my favourite solution though)!

Many thanks in advanvce
Best Regards
 
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In HTML, when you have a conrol such as:
or

The assumption is that you're using this button only for its onclick event, and the value attribute is not submitted to the server. (Note that <html:button/> gets translated to <input type="button">). Passing the value as a parameter as you're doing is about as good a way of handing it as any.
[ November 07, 2007: Message edited by: Merrill Higginson ]
 
Ranch Hand
Posts: 948
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You could also define a property on your form, define a hidden field on your jsp and then set the value of the hidden field in your onclick handler. That way you would not have to pass the value on the URL and in your action you can read the value directly from the form class.

- Brent
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic