Dynamic radio buttons matrix using Struts


Web tier: servlets, JSP, Web frameworks: Dynamic radio buttons matrix using Struts

  1. Dynamic radio buttons matrix using Struts (9 messages)

    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)

  2. object[ Go to top ]


    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"/>


    after submission of the form get the radioOptions from the form and loop over the list and do ((ABCDObject)radioOptions.getValue())
  3. still confused[ Go to top ]

    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
  4. object[ Go to top ]

    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,
  5. How I solved this?[ Go to top ]

    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?
  6. How I solved this?[ Go to top ]

    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.

  7. Use the array index[ Go to top ]

    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
    and for subsequent ones keep on increasing the index.
  8. 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">
        <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>

    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
  9. 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?
  10. 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}" >








    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