struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Heikki Hyyrö <>
Subject Re: Struts 2 and automatic ids
Date Sun, 21 Sep 2014 12:15:23 GMT
Lukasz Lenart <> 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


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

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message