File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "re:struts dynamic radio buttons" Watch "re:struts dynamic radio buttons" New topic

re:struts dynamic radio buttons

ravi sekhar sapare

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 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.*" %>
<body bgcolor="FFCC99">
<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tr><td><img src="images/BLUE_WAVE.gif" width="100%" height="36px"></td></tr>
<html:form action="/invoicedet">
<font size="5" face="arial" color="red">Select Bank</font>
<table border=2 bgcolor="99CCFF">
<logic:iterate id="bd" name="array">
<html:radio property="select" value="bd"/>
<bean:write name="bd" property="bankname"/>
<bean:write name="bd" property="agreement"/>
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.

Consultant, Sima Solutions
I agree. Here's the link:
subject: re:struts dynamic radio buttons
It's not a secret anymore!