[jboss-user] [JBoss Seam] - s:selectItems once again
w17chm4n
do-not-reply at jboss.com
Wed Oct 17 09:13:37 EDT 2007
The 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 !!!
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4096066#4096066
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4096066
More information about the jboss-user
mailing list