Results 1 to 4 of 4

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

  1. #1
    Join Date
    Oct 2005
    Posts
    5

    Default 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. #2
    Join Date
    Aug 2004
    Posts
    1,905

    Default

    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.

  3. #3
    Join Date
    Oct 2005
    Posts
    5

    Default

    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

  4. #4

    Default

    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?

Similar Threads

  1. Replies: 8
    Last Post: Oct 30th, 2012, 11:33 AM
  2. Replies: 3
    Last Post: Jun 8th, 2010, 03:27 AM
  3. Replies: 5
    Last Post: Sep 5th, 2005, 06:22 AM
  4. Replies: 1
    Last Post: May 16th, 2005, 08:48 PM
  5. Replies: 4
    Last Post: Apr 15th, 2005, 05:46 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •