s:selectItems once again
w17chm4n Oct 17, 2007 9:13 AMThe problem :
Validation Error: Value is not valid
I`ve searched the forum and I found that one way is to implement equals() and hashCode() method. So I did (well copy-pasted ;))
@Entity @Scope(ScopeType.EVENT) @Name("questionCategory") @Table(name="QuestionCategories") public class QuestionCategory implements Serializable { @Id @GeneratedValue private Long id; @NotNull @Length(min=3, max=100) private String categoryName; @OneToMany private List<Question> questionList; @Temporal(value = TemporalType.TIMESTAMP) private Date created; @Override public boolean equals(Object obj) { if (!(obj instanceof QuestionCategory)) { return false; } QuestionCategory c = (QuestionCategory) obj; return this.id == c.getId(); } @Override public int hashCode() { int result = 17; result = 37 * result + this.id.intValue(); return result; } /** Creates a new instance of QuestionCategory */ public QuestionCategory() { this.questionList = new ArrayList<Question>(); } public QuestionCategory(String categoryName) { this.categoryName = categoryName; this.questionList = new ArrayList<Question>(); } public Long getId() { return id; } public void setId(Long id) { this.id = id; } public String getCategoryName() { return categoryName; } public void setCategoryName(String categoryName) { this.categoryName = categoryName; } public List<Question> getQuestionList() { return questionList; } public void setQuestionList(List<Question> questionList) { this.questionList = questionList; } public Date getCreated() { return created; } public void setCreated(Date created) { this.created = created; } }
I have a following code in my question.xhtml
<body> <h:form> <h:outputText value="Choose existing category: "/> <h:selectOneMenu value="#{questionCategory}" required="true"> <s:selectItems value="#{questionCategoryList}" var="category" label="#{category.categoryName}" noSelectionLabel="Please Select..."/> <s:convertEntity/> </h:selectOneMenu> <h:commandButton type="submit" value="Add Question" action="#{QuestionCategoryController.addQuestion}"/> </h:form> </body>
And quess what, this still doesn`t work !
I need help !!!