| 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
|
 |
 |
|
|
subject: re:struts dynamic radio buttons
|
|
|