Uploaded image for project: 'Struts 1'
  1. Struts 1
  2. STR-2991

indexed <nested:text> does not render index properly when inside two nested <nested:iterate>

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Open
    • Major
    • Resolution: Unresolved
    • 1.2.9
    • None
    • Tag Libraries
    • None

    Description

      The name attribute of a <nested:text indexed="true"> is not rendered properly when is placed inside two nested <nested:iterate>.

      Example:

      "A MyForm contains a list of Group, and a Group contains a list of User. I want to edit the name of all users in a single page, categorized by group":

      class MyForm extends ActionForm {
      private List groups = new LazyList.decorate(new ArrayList(), new GroupsFactory());
      public List getGroups()

      { return groups }

      ;
      public List setGroups(List groups)

      { this.groups = groups; }

      ;
      };

      class Group {
      private List users = new LazyList.decorate(new ArrayList(), new UsersFactory());
      public List getUsers()

      { return users}

      ;
      public List setUsers(List users)

      { this.users = users; }

      ;
      };

      class User {
      private String name;
      public String getName()

      { return name;}

      public void setName(String name)

      { this.name = name; }

      };

      Data (pseudo-code):
      myForm
      groups = {
      Group(users =

      { "user1", "user2", "user3"}

      ),
      Group(users =

      { "user4", "user5", "user6"}

      )
      }

      I want to render this:

      <input type="text" name="groups[0].users[0].name" value="user1">
      <input type="text" name="groups[0].users[1].name" value="user2">
      <input type="text" name="groups[0].users[2].name" value="user3">
      <input type="text" name="groups[1].users[0].name" value="user4">
      <input type="text" name="groups[1].users[1].name" value="user5">
      <input type="text" name="groups[1].users[2].name" value="user6">

      The following code (code1):

      <nested:iterate name="myForm" property="groups">
      <nested:iterate property="users" >
      <nested:text property="name" indexed="true">
      </nested:iterate>
      </nested:iterate>

      renders this:

      <input type="text" name="myForm[0].groups[0].users[0].name" value="user1">
      <input type="text" name="myForm[1].groups[0].users[1].name" value="user2">
      <input type="text" name="myForm[2].groups[0].users[2].name" value="user3">
      <input type="text" name="myForm[0].groups[1].users[0].name" value="user4">
      <input type="text" name="myForm[1].groups[1].users[1].name" value="user5">
      <input type="text" name="myForm[2].groups[1].users[2].name" value="user6">

      I don't know how to avoid to render the "myForm[i]" part. The only solution I have found is to add the following getter into MyForm class. It works, but seems ugly: public BorrameForm getForm(int index)

      {return this;}

      Attachments

        Activity

          People

            Unassigned Unassigned
            bocca bocca romel
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated: