• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

re:struts dynamic radio buttons

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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>
 
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
He was giving me directions and I was powerless to resist. I cannot resist this tiny ad:
Clean our rivers and oceans from home
https://www.kickstarter.com/projects/paulwheaton/willow-feeders
reply
    Bookmark Topic Watch Topic
  • New Topic