You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by sanrosh95 <sa...@sherwin.com> on 2009/03/10 16:05:22 UTC
Struts 2 Type Conversion HashSet Object within the List of Object
Hi ,
I am able to display List and HashSet within List correctly from Action to
JSP .But when Form is Submitted i m getting error while setting SubCats
within the Category Object
I have addded Type Conversion for Category and its working fine .How to add
Conversion for SubCategory Within the Category
KeyProperty_categorys=id
Element_categorys=com.model.Category
CreateIfNull_categorys=true
I have 2 Clases
Public Class Category {
private Long id;
private String name;
private Set SubCats = new HashSet(0);
public Long getId() {
return this.id;
}
public void setId(Long id) {
this.id = id;
}
public String getName() {
return this.name;
}
public void setName(String name) {
this.name = name;
}
public Set getSubCats() {
return this.SubCats ;
}
public void setSubCats(Set SubCats) {
this.SubCats = SubCats;
}
}
Public Class SubCategory {
private Long id;
private String name;
private boolean selected = false;
public Long getId() {
return this.id;
}
public void setId(Long id) {
this.id = id;
}
public String getName() {
return this.name;
}
public void setName(String name) {
this.name = name;
}
public boolean isSelected() {
return selected;
}
public void setSelected(boolean selected) {
this.selected = selected;
}
}
My Action Class
public class EditAction extends ActionSupport {
private List categorys;
public List getCategorys() {
return categorys;
}
public void setCategorys(List categorys) {
this.categorys = categorys;
}
}
My JSP :
<s:iterator value="categorys" status="stat" >
<tr>
<td><s:property value="name" />
<s:hidden value="%{id}" name="categorys[%{#stat.index}].id"
/>
<s:hidden value="%{name}"
name="categorys[%{#stat.index}].name" />
</td>
</tr>
<s:iterator value ="SubCats" status="st" >
<tr>
<td>
<s:hidden value="%{id}"
name="categorys[%{#stat.index}].SubCats[%{#st.index}].id" />
<s:hidden value="%{name}"
name="categorys[%{#stat.index}].SubCats[%{#st.index}].name" />
<s:checkbox
name="categorys[%{#stat.index}].SubCats[%{#st.index}].selected"
value="%{selected}" theme="simple" />
</td>
</tr>
</s:iterator>
</s:iterator>
--
View this message in context: http://www.nabble.com/Struts-2-Type-Conversion-HashSet-Object-within-the-List-of-Object-tp22436263p22436263.html
Sent from the Struts - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org