This week's book giveaway is in the Java 8 forum.
We're giving away four copies of Java 8 in Action and have Raoul-Gabriel Urma, Mario Fusco, and Alan Mycroft on-line!
See this thread for details.
The moose likes Struts and the fly likes re:struts dynamic radio buttons Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "re:struts dynamic radio buttons" Watch "re:struts dynamic radio buttons" New topic
Author

re:struts dynamic radio buttons

ravi sekhar sapare
Greenhorn

Joined: Mar 24, 2008
Posts: 1
hi all,

I have a small doubt in my application, my requirement is to get a "single selectible row", I generated a radio button for each row as i got data from the database using <logic:iterate .../> tag,but when i select any row the bean is going to bind the last iterated value, please can anyone clear my doubt how to enable the row when i select the radio button and on submit the bean should bind that selected row.my code is:

<%@ taglib uri="/WEB-INF/struts-html" prefix="html" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@page import="java.util.*" %>
<html:html>
<head>
<title></title>
</head>
<body bgcolor="FFCC99">
<center>
<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tr><td><img src="images/BLUE_WAVE.gif" width="100%" height="36px"></td></tr>
</table>
<html:form action="/invoicedet">
<br><br>
<font size="5" face="arial" color="red">Select Bank</font>
<br><br>
<table border=2 bgcolor="99CCFF">
<tr>
<th><%="select"%></th>
<th><%="BankName"%></th>
<th><%="Agreement"%></th>
</tr>
<logic:iterate id="bd" name="array">
<tr>
<td>
<html:radio property="select" value="bd"/>
</td>
<td>
<bean:write name="bd" property="bankname"/>
</td>
<td>
<bean:write name="bd" property="agreement"/>
</td>
</tr>
</logic:iterate>
</table>
</html:form>
</center>
</body>
</html:html>
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
The problem is with your html:select tag. Specifying value="bd" in this case represents the literal string "bd", not the variable bd. So, when placed in a logic:iterate loop makes it so each radio button sends the same value when pressed, which is not what you want. What I suspect you do want is to have the select variable contain some unique value when a button is pressed for each row. I don't know what properties your bd object has, but if it has some sort of id property that uniquely identifies it, that would be a good candidate. If this is the case, below is an example of how you might change your tag:

The above takes advantage of the fact that specifying a body for an html:radio tag is the same as specifying a value attribute.


Merrill
Consultant, Sima Solutions
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: re:struts dynamic radio buttons
 
Similar Threads
problem with using iterate!
Jsp and database using the logic:iterate tag
Retriving values from html:checkbox in a jsp
Attempted a bean operation on a null object.
JspTranslate: End of content reached while more parsing required: tag nesting error?.