struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Heikki Hyyrö <heikki.hy...@uta.fi>
Subject Re: Struts 2 and automatic ids
Date Sun, 21 Sep 2014 12:15:23 GMT
Lukasz Lenart <lukaszlenart@apache.org> kirjoitti 21.9.2014 kello 11.48:
> Can you prepare some exact example app?


Would the example snippet at the bottom be enough? It shows a slightly cleaned version of
one form we use. The form basically consists of a table that lists the users of the system.
Each user can be assigned to a user group. This form sends two arrays to the action updateGroups:
one is ”userIds”, which contains the user ids, and the other one is ”groupIds”, which
contains the group ids (which may be changed via the select-list in the last column).

Struts generates identical id for each input field that gives values to these two lists. For
example if there are 500 users, the html-code output by Struts will contain 500 snippets that
look like:

<input type="hidden" name="userIds" value="4267" id="updateUserGroups_userIds"/><select
name="groupIds" id="updateUserGroups_groupIds">

Each of these snippets will differ only in what is the value of the first hidden field. WWW
validator will then output hundreds of errors of form "Duplicate ID updateUserGroups_groupIds”
and "Duplicate ID updateUserGroups_userIds”.

In this particular case the problem might(?) go away if the form used explicit index notation
with the array names ”userIds" and "groupIds", but as far as I know (e.g. based on the book
Struts 2 in Action), the practice of populating arrays without explicit indexing is quite
normal.

-Heikki


<s:form action="updateGroups">
    <table class="tablesorter" id=”userTable">
      <thead>
        <tr>
          <th>Name</th>
          <th>Login</th>
          <th>Email</th>
          <th>Group</th>
        </tr>
      </thead>
      <tbody>
        <s:iterator var=”user" value=”users">
          <tr>
            <td>
              <s:url action="viewUser" var="viewUserUrl">
                <s:param name="userId" value="%{#user.id}" />
              </s:url>
              <s:a href="%{viewUserUrl}">
                ${user.lastName}, ${user.firstName}
              </s:a>
            </td>
            <td>${user.login}</td>
            <td><a href="mailto:${user.email}">${user.email}</a></td>
            <td>
              <s:hidden name="userIds" value="%{#user.id}" />
              <s:select list="groupList" name="groupIds" value="%{groupValues[#user.id]}"
/>
            </td>
          </tr>
        </s:iterator>
      </tbody>
    </table>
    <p>
      <input type="submit" value=”Save changes" />
    </p>
  </s:form>




---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Mime
View raw message