I am having a problem with selectonemenu, it seems to be all working fine but the component returns object value hashes instead of the actual values themselves. The below i provide a screen shot and backing bean with xhtml code
Thanks for your help in advance!
Screenshot
http://www.imagesup.net/?di=3141102127810
createCategory.xhtml
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:p="http://primefaces.org/ui">
<h:head>
<title>Create Category</title>
</h:head>
<h:body>
<h:outputText value="Create a new category" />
<h:form id="createcat">
<p:inputText id="catname" value="#{categorycontroller.categoryName}"
required="true" label="Category Name" />
<p:watermark for="catname" value="Category Name" id="watermark" />
<p:inputText id="catdesc"
value="#{categorycontroller.categoryDescription}" required="true"
label="Category Description" />
<p:watermark for="catdesc" value="Category Description"
id="watermark2" />
<h:commandButton action="#{categorycontroller.createCategory()}"
value="Create Category" />
</h:form>
<h:outputText value="List of categories" />
<p:dataList value="#{indexcontroller.categoryList}" var="val">
<p:column>
<f:facet name="header">Categories</f:facet>
<h:outputLink value="displayCategory.jsf?catId=#{val.catid}">#{val.categoryName}</h:outputLink>
</p:column>
</p:dataList>
<h:outputText value="Create a new post" />
<h:form id="createpost">
<p:selectOneMenu value="#{categorycontroller.categoryName}"
style="width:150px">
<f:selectItem itemLabel="Category" itemValue=""
noSelectionOption="true" />
<f:selectItems value="#{categorycontroller.categoryList}" />
</p:selectOneMenu>
<p:inputText id="postname" value="#{categorycontroller.postnametxt}"
required="true" label="Post Name" />
<p:watermark for="postname" value="Post Name" id="watermarkpost" />
<h:commandButton action="#{categorycontroller.createPost()}"
value="Create Post" />
</h:form>
</h:body>
</html>
CategoryController.java
@ManagedBean(name = "categorycontroller")
@RequestScoped
public class CategoryController implements Serializable{
/**
*
*/
private static final long serialVersionUID = -4375358965234910850L;
@ManagedProperty(value="#{portalService}")
PortalService portalService;
public void createCategory(){
Category category = new Category();
category.setCategoryName(categoryName);
category.setCategoryDescription(categoryDescription);
portalService.createCategory(category);
}
public void createPost(){
Category category = new Category();
category.setCatid(catid);
Post post = new Post();
post.setPostname(postnametxt);
post.setCategory(category);
portalService.createPost(post);
}
private int catid;
private String categoryName;
private String categoryDescription;
private String postnametxt;
private String selectedCategory ="";
private List<Category> categoryList;
private List<Post> postList;
public PortalService getPortalService() {
return portalService;
}
public void setPortalService(PortalService portalService) {
this.portalService = portalService;
}
public List<Post> getPostList() {
return postList;
}
public void setPostList(List<Post> postList) {
this.postList = postList;
}
public int getCatid() {
return catid;
}
public void setCatid(int catid) {
this.catid = catid;
}
public String getCategoryName() {
return categoryName;
}
public void setCategoryName(String categoryName) {
this.categoryName = categoryName;
}
public String getCategoryDescription() {
return categoryDescription;
}
public void setCategoryDescription(String categoryDescription) {
this.categoryDescription = categoryDescription;
}
public List<Category> getCategoryList() {
return portalService.getAllCategories();
}
public void setCategoryList(List<Category> categoryList) {
this.categoryList = categoryList;
}
public String getPostnametxt() {
return postnametxt;
}
public void setPostnametxt(String postnametxt) {
this.postnametxt = postnametxt;
}
public String getSelectedCategory() {
return selectedCategory;
}
public void setSelectedCategory(String selectedCategory) {
this.selectedCategory = selectedCategory;
}
}