Announcement Announcement Module
Collapse
No announcement yet.
Radio Button [u]group[/u] on dynamically generated web form Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Radio Button [u]group[/u] on dynamically generated web form

    Ok,
    I have a simple table, generated dynamically from a collection of user details. Each row corresponds to a user, with a tick box to allow user to be selected. This works fine if I use check boxes, and binds correctly etc.

    I'd like to change the implementation slightly to allow only a single user to be selected using radio buttons in a button group. I use...

    Code:
    <c&#58;choose>
        <c&#58;when test="$&#123;fn&#58;length&#40;users.userList&#41; != '0'&#125;">
              <form method="post">
                            <table>
                                <tr>
                                    <th><fmt&#58;message key="form.select" /></th>
                                    <th><fmt&#58;message key="user.username" /></th>
                                    <th><fmt&#58;message key="user.firstname" /></th>
                                    <th><fmt&#58;message key="user.surname" /></th>
                                </tr>
                                <c&#58;forEach items="$&#123;users.userList&#125;" var="user" varStatus="counter">
                                    <tr>
                                        <spring&#58;bind path="users.userList&#91;$&#123;counter.index&#125;&#93;.selected" >
                                            <td>
                                                <input type="radio" 
                                                <c&#58;if test="$&#123;status.value&#125;">
                                                    checked="checked"
                                                </c&#58;if>
                                                name="$&#123;status.expression&#125;" />
                                            </td>
                                        </spring&#58;bind>
                                        <td><c&#58;out value="$&#123;user.username&#125;" /></td>
                                        <td><c&#58;out value="$&#123;user.firstName&#125;" /></td>
                                        <td><c&#58;out value="$&#123;user.surname&#125;" /></td>
                                    </tr>
                                </c&#58;forEach>
                            </table>
                            <input type="submit" value="<fmt&#58;message key="modifyuser.submit" />" align="center" />
                            <input type="reset" value="<fmt&#58;message key="modifyuser.reset" />" align="center" />
                        </form>
                    </c&#58;when>
                    <c&#58;otherwise>
                        <fmt&#58;message key="selectuser.nousers" />
                    </c&#58;otherwise>
                </c&#58;choose>

    My problem is that this requires the 'name' attribute of each button in the group to be the same. But
    Code:
     name="$&#123;status.expression&#125;"
    generates
    Code:
    userList&#91;0&#93;.selected
    userList&#91;1&#93;.selected
    etc.
    breaking the selection group.


    Any ideas of how to get around this?

    Thanks in advance.

    David.

  • #2
    yeah, you don't want to use a Collection If you only want a single user selected then your command should have a setUser(User) method. You could use formBackingObject to populate the model with all users.

    HTH.

    Comment


    • #3
      Thanks, that's useful...but I'm quite new to all this.

      You could use formBackingObject to populate the model with all users
      Could you shed a little light on how that would work? I thought that formBackingObject added a single object to the model called <commandName value>. So how do I add 'all users' to the model using this?

      Did you mean referenceData() ? And then I have a command object that binds to the selected user? How would the jsp side of that work?

      Many thanks,

      David

      Comment


      • #4
        i assume he does mean "formBackingObject". then use spring bind tags to bind the command.selectUser.id for the path, of the select object, and have the select options generated from the formBacking collection with the ID as the option value.

        does that help?

        Comment

        Working...
        X