-
Dynamic radio buttons matrix using Struts (9 messages)
- Posted by: Adolfo Gonzalez
- Posted on: February 02 2005 14:34 EST
Hello, I’ve a problem, please if somebody could help me I’ll really appreciate it.
I have a dynamic matrix with radio buttons, only the number of rows could change. The matrix is as follows, it has 4 static columns of radio buttons and for each row I can select only one (radio button):
Skill 1 O O O O
Skill 2 O O O O
Skill 3 O O O O
Skill n O O O O
How could I store the selected radio buttons in the ActionForm? Whichever information you have that it could help me, I’d really appreciate it.Threaded Messages (9)
- object by Ash H on February 02 2005 14:45 EST
- still confused by Stu Smiley on April 18 2005 11:19 EDT
- object by Aravind Iyengar on June 08 2005 17:40 EDT
- How I solved this? by Biswa Das on June 08 2005 20:27 EDT
- How I solved this? by Aravind Iyengar on June 08 2005 21:24 EDT
- Use the array index by Biswa Das on June 09 2005 10:41 EDT
- How I solved this? by Aravind Iyengar on June 08 2005 21:24 EDT
- Re: Dynamic radio buttons matrix using Struts by Zdenek Velart on September 17 2005 08:20 EDT
- Re: Dynamic radio buttons matrix using Struts by Madalina Cerchia on March 19 2007 06:10 EDT
- Re: Dynamic radio buttons matrix using Struts by Tejashri Nagulpelli on April 01 2011 07:14 EDT
-
object[ Go to top ]
- Posted by: Ash H
- Posted on: February 02 2005 14:45 EST
- in response to Adolfo Gonzalez
Hi,
Create an ABCDObject which will hold the column values(firstOptionVal,secondOptionVal,value)for two such radio options and the actuAl selected value.
In the form create an arrayList (radioOptions)which will hold these Objects.
In jsp use <nested:iterate> tag to iterate over this arrayList
<nested:iterate property="radioOptions" name="abcdForm">
<nested:define id="first" property="firstOptionVal" type="java.lang.String"/>
<nested:radio value='<%=first%>' property="value"/>
<nested:define id="second" property="secondOptionVal" type="java.lang.String"/>
<nested:radio value='<%=second%>' property="value"/>
</nested:iterate>
after submission of the form get the radioOptions from the form and loop over the list and do ((ABCDObject)radioOptions.getValue()) -
still confused[ Go to top ]
- Posted by: Stu Smiley
- Posted on: April 18 2005 11:19 EDT
- in response to Ash H
I have the exact same problem as Adolfo has, but I am not sure I understand the explanation. In the ABCDObject, is there a
private String selected -
object[ Go to top ]
- Posted by: Aravind Iyengar
- Posted on: June 08 2005 17:40 EDT
- in response to Ash H
Hi Ash,
Could you be more descriptive on this as I too have the same problem and I am totally confused on this usage. if possible can you send me a sample code containing the JSP, action and form bean java files.
Thanks and regards, -
How I solved this?[ Go to top ]
- Posted by: Biswa Das
- Posted on: June 08 2005 20:27 EDT
- in response to Adolfo Gonzalez
for each row use a
hiddden parameter letsay
<input type="hidden" name="radio_row_value"/> and use as some one already suggested approach to generate radio grid with indexed iteration. And upon click of each row one event should populate the corresponding hidden parameter
In Action form declare
String[] radio_row_value; and forget about all those radio buttons.
Bet me there is no direct solution to map it to ActionForm.
It is a long standing issue? -
How I solved this?[ Go to top ]
- Posted by: Aravind Iyengar
- Posted on: June 08 2005 21:24 EDT
- in response to Biswa Das
Hi Biswas,
But how should this be achieved as there may a number of <input type="hidden"> fields with same name and how should I identify this field for every row in JavaScript.
Please let me know.
Aravind -
Use the array index[ Go to top ]
- Posted by: Biswa Das
- Posted on: June 09 2005 10:41 EDT
- in response to Aravind Iyengar
When the variable name is same in any html page they are treated as array.
so for the first row access the hidden parameter as
radio_row_value[0]
and for subsequent ones keep on increasing the index. -
Re: Dynamic radio buttons matrix using Struts[ Go to top ]
- Posted by: Zdenek Velart
- Posted on: September 17 2005 08:20 EDT
- in response to Adolfo Gonzalez
Hi, I had a similar problem today and found a simple solution. I use combination of Struts tags and JSTL.
I have n rows, where every row has some text and 3 radio buttons. My HTML code looks:
<c:forEach var="item" items="${roles}" varStatus="status">
<tr>
<td>${item.name}</td>
<td><html-el:radio property="values[${status.index}]" value="NO">radioButtonMessage1</html-el:radio></td>
<td><html-el:radio property="values[${status.index}]" value="RO">radioButtonMessage2</html-el:radio></td>
<td><html-el:radio property="values[${status.index}]" value="EW">radioButtonMessage3</html-el:radio></td>
</tr>
</c:forEach>
The property value is in ActionForm defined:
private String[] values = new String[0];
and i have two setters:
public void setValues(String[] values) {
this.values = values;
}
and, which is actualy used when submitting form
public void setValues(int id, String value) {
if (this.values.length - 1 <= id) {
String[] array = new String[id + 1];
for (int i = 0; i < this.values.length; i++) {
array[i] = this.values[i];
}
this.values = array;
}
this.values[id] = value;
}
because i don't know how many of elements there will be, i have to check every time if there is big
enough array to store the data. If not i extends the array to desired size.
This can be used also to populate the page with preset radio button. In Action you only have to set
MyForm f = new MyForm();
f.setValues(new String[] {"NO", "RO", "NO", "EW"});
Hope, this will help you -
Re: Dynamic radio buttons matrix using Struts[ Go to top ]
- Posted by: Madalina Cerchia
- Posted on: March 19 2007 06:10 EDT
- in response to Zdenek Velart
Thanks for your post. I have used your code to create a list of radio buttons. But I have problems when keeping the selections? How can I read the selected radio's? -
Re: Dynamic radio buttons matrix using Struts[ Go to top ]
- Posted by: Tejashri Nagulpelli
- Posted on: April 01 2011 07:14 EDT
- in response to Zdenek Velart
Hi Zdenek
I used the code you provided but i'm not getting a proper page.
I have 24 rows, each created using the for loop as follows:
<c:forEach var="spreadsheet" items="${spreadsheetAEPOList}" >
<tbody>
<tr>
<td>....</td>
<td>..<td>
</tr>
</tbody>
</c:forEach>
and each row has two radio buttons to be displayed, can you please help me how would i give 24 diffrent propertis for each row's radio button and how would i write logic for each selection of the button