aspose file tools*
The moose likes Struts and the fly likes JSP Radio button value retrieval Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "JSP Radio button value retrieval" Watch "JSP Radio button value retrieval" New topic
Author

JSP Radio button value retrieval

M sallu
Ranch Hand

Joined: Dec 13, 2009
Posts: 42
I have thee columns in table, Id, Date and Description.

From the main page I am setting all values and forwarding the struts action to maint page

request.setAttribute("specialResult", allItems);
return mapping.findForward("maint"); //points to Maint.jsp in struts-config.xml

**********My Maint.jsp page *********
.....

<table border="2" cellspacing="0" cellpadding="5">
<logic:notEmpty name="specialResult" scope="request">
<logic:iterate name="specialResult" id="specialResult"
indexId="index">
<tr align="center">
<td width="15%"><INPUT type="radio" value="upId"
name="radio"/></td>
<td width="15%"><bean:write name="specialResult"
property="upholidayDate" /></td>
<td width="15%"><bean:write name="specialResult"
property="upholidayDesc" /></td>
</tr>
</logic:iterate>
</logic:notEmpty>

</table>
<table align="center">
<tr>
<td valign=top><input type="button" property="update"
value="UPDATE" onclick="doUpdate()"></td>
<td valign=top><input type="button" property="delete"
value="DELETE" onclick="doDel()"></td>
<td valign=top><input type="button" property=cancel
value="GO BACK" onclick="doCancel()"></td>
</tr>
</table>
.....

I need to retrieve that "upId" which the radio button is selected.

I cannot set the radio button value as value="<%=upId%>" as the JSP will not load.

Can i get that radio button upId (this is primary key in table) within my action .

String upId = request.getParameter("upId");
//but this is retrieving the first row id and not the selected id.

Please help.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61180
    
  66

Please be sure to use code tags when posting code to the forums. Unformatted or unindented code is extremely hard to read and many people that might be able to help you will just move along to posts that are easier to read. Please click this link ⇒ UseCodeTags ⇐ for more information.

Properly indented and formatted code greatly increases the probability that your question will get quicker, better answers.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61180
    
  66

Also, please be sure to ask Struts questions in the Struts forum. I have moved this post there for you.
M sallu
Ranch Hand

Joined: Dec 13, 2009
Posts: 42
My maint.jsp page



My doDel Action
*************
M sallu
Ranch Hand

Joined: Dec 13, 2009
Posts: 42
Any help please, how to send the random "upId" retrieved from database to my action class for the radio button selected?
mahesh shinde
Ranch Hand

Joined: Jul 24, 2009
Posts: 69

If your list Contain upId Property then try the following code
No need of this <%String upId = request.getParameter("upId"); %>

and in your action class get the value using form bean

Fidel Edwards
Ranch Hand

Joined: Mar 19, 2008
Posts: 231
M sallu wrote:Any help please, how to send the random "upId" retrieved from database to my action class for the radio button selected?


Hi Sallu,

Please see this post. Radio Button Values and especially read the suggestion given by Dom Lassy. I hope that would be helpful for you.



God Gave Me Nothing I Wanted, He Gave Me Everything I Needed.
OCPJP6
M sallu
Ranch Hand

Joined: Dec 13, 2009
Posts: 42
I am not able to check my radio buttons...they are not selectable

M sallu
Ranch Hand

Joined: Dec 13, 2009
Posts: 42
I figured, there was name attibute missing



And my struts action class...shall I just getParameter and get the values

Fidel Edwards
Ranch Hand

Joined: Mar 19, 2008
Posts: 231
M sallu wrote:I figured, there was name attibute missing


Good Sallu! It is good that you are trying hard, understanding and removing the shortcomings.


Please add name attribute in your radio button



Then only you can access this radio button's value in your Action class as
M sallu
Ranch Hand

Joined: Dec 13, 2009
Posts: 42
Yes, it worked and I am getting variable value for my radio button by


Thanks for all the help
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JSP Radio button value retrieval