2

I am using Struts2. I have a hashset in my pojo. I am trying to submit values to the hashset. There is no way i can change my collection type to list.

here is pojo

Item{
Set<Person> personCollection;
long itemCode;

    public void setItemCode(long itemCode)
    {
        this.itemCode=itemCode;
    }
    public long getitemCode()
    {
        return itemCode;
    }
    public void setPersonCollection(Set<Person>personCollection)
    {
        this.personCollection=personCollection;
    }
    public Set<Person> getPersonCollection()
    {
        return personCollection;
    }
}

Person{
    String name;
    public void setName(String name)
    {
        this.name=name;
    }
    public String getName()
    {
        return name;
    }
}

Action

SubmitItemAction
{
     private Item item;
     public getItem()
     {
          return item;
     }
     public setItem(Item item)
     {
          this.item=item;
     }
     public String submitItem()
     {
           dao.submit(item);
     }
}

jsp

  <s:text name=item.personCollection[0].name/>
  <s:text name=item.personCollection[1].name/>

so this doesnt work. When i submit my jsp with above snippet it gives error, its not able to populate personCollection from Item.

So what should be naming convention in jsp. Like if personCollection would have been a list I could have used item.personCollection[0].someProperty. But how do you set the name for collection of type set.

kunal
  • 779
  • 6
  • 25

1 Answers1

2

Well in your submit action use the list and then you can use this list inside jsp with index.

You cannot use set here as set cannot be accessed using indexes

In your business logic convert the list into set as you may require set for further orm.

Amol Ghotankar
  • 2,008
  • 5
  • 28
  • 42
  • for time being this looks fine. But i am looking for more generic solution. As there could be multiple instances of sets being using the POJOs. Thanks for the reply. – kunal May 24 '12 at 13:01
  • Well you are correct. May be try using iterator tag of struts. Personally I have failed to do so and needed this at only couple of places so. Update with your answer if you get any success. – Amol Ghotankar May 24 '12 at 13:13
  • i am using iterator tag in the jsp. Sure i will update the post if better solution is worked out. – kunal May 24 '12 at 13:16