Hi all,
I've experienced a strange problem with managed beans having primitive data type fields.
This is the scenario:
// Managed Bean
public class FormBean implements Serializable {
private VO vo; // A value object
private List list2 = new ArrayList();
public FormBean() {
// Initialization
....
}
public void changeOptions() {
// Populate list2 reading data from the database
...
}
public List getList2() {
return list2;
}
public void setList2(List list2) {
this.list2 = list2;
}
public VO getVo() {
return vo;
}
public void setVo(VO vo) {
this.vo = vo;
}
}
public class VO implements Serializable {
private int id;
private String name;
private OtherVO vo; // An other Value Object similar to VO
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public OtherVO getVo() {
return vo;
}
public void setVo(OtherVO vo) {
this.vo = vo;
}
}
// Managed Bean
public class List1 implements Serializable {
private List list1 = new ArrayList();
public List1() {
// Initialize list1:
SelectItem item = new SelectItem(1, "Item 1");
list1.add(item);
item = new SelectItem(2, "Item 2");
list1.add(item);
item = new SelectItem(3, "Item 3");
list1.add(item);
...
}
public List getList1() {
return list2;
}
public void setList1(List list1) {
this.list1 = list1;
}
}
The jsp contains this code:
<h:selectOneMenu value="#{formBean.vo.id}" id="list1" required="true" >
<f:selectItems value="#{list1Bean.list1}"/>
<a4j:support event="onchange" action="#{formBean.changeOptions}"
ajaxSingle="true" reRender="list2" />
</h:selectOneMenu>
<h:selectOneMenu value="#{formBean.vo.vo.id}" id="list2" required="false">
<f:selectItems value="#{formBean.list2Items}"/>
</h:selectOneMenu>
If I select a value of list1, an exception is thrown: java.lang.IllegalArgumentException.
If I change all the int fields in Integer, it works fine. Why? Ajax4sf does not support autoboxing?
Thanks
Pippo