This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Java Interview Guide and have Anthony DePalma on-line!
See this thread for details.
The moose likes Struts and the fly likes Buttons EventHandler and Property-Setting Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Buttons EventHandler and Property-Setting" Watch "Buttons EventHandler and Property-Setting" New topic

Buttons EventHandler and Property-Setting

Ren� Thol

Joined: Nov 22, 2006
Posts: 4
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
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
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 ]

Consultant, Sima Solutions
Brent Sterling
Ranch Hand

Joined: Feb 08, 2006
Posts: 948
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
I agree. Here's the link:
subject: Buttons EventHandler and Property-Setting
It's not a secret anymore!