SelectOneMenu and converters do not work
Hi all,
I am developing a weblog platform. Users can have many blogs. I wrote an edit.jsp page where users add or edit articles. Here users can choose on which blog they want to publish their articles.
entity bean for user
publicclass Userimplements Serializable{
...
@Transient
public List<SelectItem> getBlogItems(){
List<SelectItem> blogItems =new LinkedList<SelectItem>();
for (Blog blog: this.getBlogs()){
blogItems.add(new SelectItem(blog, blog.getAbout()));
}
return blogItems;
}
...
}
converter
publicclass BlogConverterimplements Converter{
public Object getAsObject(FacesContext context, UIComponent component, String value){
Integer id =new Integer(value);
Blog blog = JLogPlatform.getInstance().
getBlogs().getBlog(id.intValue());
return blog;
}
public String getAsString(FacesContext context, UIComponent component, Object value){
return ((Blog)value).getId()+"";
}
}
Piece of code in page edit.jsp
<h:selectOneMenu id="selectBlog" required="true"
value="#{articleBean.blog}"
converter="BlogConverter" >
<f:selectItems value="#{articleBean.user.blogItems}" />
</h:selectOneMenu>
...
<h:commandButton value="Save"
action="listArticles"
actionListener="#{articleBean.saveArticle}" />
Here articleBean.blog is a field of type Blog and articleBean is a managed backing bean.
I can view page edit.jsp, however when I click on button "Save" to update or add an article, I get the following error:
java.lang.IllegalArgumentException: Value binding'#{articleBean.user.blogItems}'of UISelectItems with component-path{Component-Path : [Class: javax.faces.component.UIViewRoot,ViewId: /protected/editArticle.jsp][Class: javax.faces.component.html.HtmlForm,Id: _id0][Class: javax.faces.component.html.HtmlPanelGrid,Id: _id1][Class: javax.faces.component.html.HtmlSelectOneRadio,Id: selectBlog][Class: javax.faces.component.UISelectItems,Id: _id4]} does not reference an Object of type SelectItem, SelectItem[], Collection or Map but of type :null
The following code is the saveArticle method of articleBean bean
publicvoid saveArticle(ActionEvent event){
this.setModificationDate(new Date());
JLogPlatform.getInstance().
getArticles().
addArticle(this);
}
any idea?
Thanks,
Marco

