Meaningless Drivel is fun!*
The moose likes Struts and the fly likes Selected radio button value to be send to action class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Selected radio button value to be send to action class" Watch "Selected radio button value to be send to action class" New topic
Author

Selected radio button value to be send to action class

Maan Suraj
Ranch Hand

Joined: Dec 20, 2007
Posts: 299
I have a radio button which retrieves value from the property of a form. I need to send the value of the radio button to the action class?How can i do that? I need to send the value of only the selected radio button and not all. Can i do it <html:hidden> tag? If yes, how?

Also how to send the label of the radio button selected? Label of a particluar radio button is also populated from the property of a form?

Man Suraj
Someone says "Impossible is nothing". The man next him says "Let me see you licking your elbow tip!"
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30356
    
150

Maan,
The value of the selected radio button is already submitted. If you need the label too, you do need a hidden field.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Maan Suraj
Ranch Hand

Joined: Dec 20, 2007
Posts: 299
Thanks Jeanne....

But it would have been great if you could expain this to me with a small example....

As i am not very clear....
What iam doing is iam selecting a radio button and clicking submit.

My code is something like as mentioned below
<logic:iterate>
<for label>
//below is for label

<bean:write name="abcForm" propery=empid>

//below is the radio button and its value

<html:radio name="currenty i dont care" id="currently idontcare" value=<%="empName.toString" />
</logic:iterate>

Both empName and empid are properties of the form.


My code is something like above, if not exactly the same...
Now i select a radio button from the list of radios displayed ,and clicks submit.

On click of submit, it calls javascript, form where it forwards to a particular action class.Then question here is how can i send both "empId" and "empName" values?
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

This seems less a Struts question than a JavaScript question, no?
Maan Suraj
Ranch Hand

Joined: Dec 20, 2007
Posts: 299
ok...it is...but i kept it here as i thought we are populating the values of radio button etc through struts tags. Anyways , can anyone please help?
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

...

I guess you'd have to set the onclick handler of the radio button to a JavaScript function that sets the hidden field with the value of the name.
Maan Suraj
Ranch Hand

Joined: Dec 20, 2007
Posts: 299



Now i will just try to show how its gets displayed on the screen (just look and feel)

EmpID 0200110035 o Manish
EmpID 0200110093 o Rajesh

Now suppose i select the first radio button , then i am able to retrieve value of it (i.e here 'Manish') , but NOT the label '0200110035'


David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Sure there is.

Look: you're asking how to do something in JavaScript, which isn't Struts. *You* have to build the JavaScript method call that sets the hidden field with the employee name. Here's some pseudo-code:OTOH, if you have the empId, it would seem like you don't really need the empName.
 
Don't get me started about those stupid light bulbs.
 
subject: Selected radio button value to be send to action class