Win a copy of Event Streams in Action this week in the Java in General forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
  • Paul Clapham
  • Knute Snortum
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Ron McLeod
  • Piet Souris
  • Stephan van Hulst
  • Carey Brown
  • Tim Holloway
  • Frits Walraven
  • Ganesh Patekar

Buttons EventHandler and Property-Setting

Posts: 4
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
In HTML, when you have a conrol such as:

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
  • 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
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!