Note that there are some explanatory texts on larger screens.

plurals
  1. POstruts 2 collection type conversion problem
    primarykey
    data
    text
    <p>I've trouble using type conversion in struts 2 to convert collection of bean. I've following action class : </p> <pre><code>@Validation() @Conversion() public class HelloWorldAction extends ActionSupport { private List&lt;HelloBean&gt; helloBeans = new ArrayList&lt;HelloBean&gt;(); public String execute() throws Exception { System.out.println(helloBeans); return SUCCESS; } public List&lt;HelloBean&gt; getHelloBeans() { return helloBeans; } @TypeConversion(rule = ConversionRule.COLLECTION, converter = "foo.HelloBean") public void setHelloBeans(List&lt;HelloBean&gt; helloBeans) { this.helloBeans = helloBeans; } } </code></pre> <p>and my bean class : </p> <pre><code>public class HelloBean { private String name; private Integer age; public String getName() { return name; } public void setName(String name) { this.name = name; } public Integer getAge() { return age; } public void setAge(Integer age) { this.age = age; } } </code></pre> <p>and my JSP file : </p> <pre><code>&lt;s:form action="helloWorld"&gt; &lt;s:textfield name="helloBeans.name" label="name1"/&gt; &lt;s:textfield name="helloBeans.name" label="name2" /&gt; &lt;s:textfield name="helloBeans.age" label="age1"/&gt; &lt;s:textfield name="helloBeans.age" label="age2"/&gt; &lt;s:submit /&gt; &lt;/s:form&gt; </code></pre> <p>When process has been submitted, struts always give me 4 object, instead of 2 object inside collection. I know other workaround using index in property will solve problem, but for my case i need collection to be dynamic. Is there way to solve this kind of issue ?</p> <p>I've tried others annotation as well : </p> <pre><code>@Element(value =foo.HelloBean.class ) @CreateIfNull( value = true ) @KeyProperty( value = "name" ) private List&lt;HelloBean&gt; helloBeans = new ArrayList&lt;HelloBean&gt;(); </code></pre> <p>but none of these worked</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload