How to insert a value into Set collection in Struts 2

前端 未结 1 403
臣服心动
臣服心动 2020-12-03 12:50

I am doing a project using Struts2 and I have a problem assigning a set collection.

Here\'s my Action (I eliminated the irrelevant part)

public class         


        
相关标签:
1条回答
  • 2020-12-03 13:45

    Set is a Collection and as any other collection could be indexed by a property.

    @Element(value = Student.class)
    @Key(value = Integer.class)
    @KeyProperty(value = "id") 
    @CreateIfNull(value = true)
    private Set<Student> students = new HashSet(0);
    //getter and setter, also for Student class that should have Integer id.
    

    in JSP

    <s:iterator value="students " var="student">
      <s:textfield name="students(%{#student.id}).name" />
    </s:iterator>
    

    More about this see

    Indexing a collection by a property of that collection.

    It is also possible to obtain a unique element of a collection by passing the value of a given property of that element. By default, the property of the element of the collection is determined in <Class>->conversion.properties using KeyProperty_xxx=yyy, where xxx is the property of the bean Class that returns the collection and yyy is the property of the collection element that we want to index on.

    0 讨论(0)
提交回复
热议问题