-
1. Re: Value not valid error
cbensemann Jul 4, 2010 7:55 PM (in response to harsh4u89)Can you post the code you are trying to use? Generally this error shows up because the object that is posted back does not match the one that you have in your jsf model. Sometimes implementing equals and hashcode can help depending on what you are trying to do.
-
2. Re: Value not valid error
harsh4u89 Jul 5, 2010 4:40 AM (in response to harsh4u89)My code
home.xhtml
<h:form > <h:panelGrid columns="2"> Name:<h:inputText id="name" value="#{stud.name}" /> RollNo:<h:inputText id="rollno" value="#{stud.rollNo}" /> <h:outputLabel for="branch">Branch</h:outputLabel> <h:selectOneMenu id="branch" value="#{stud.masterBranch}" > <s:selectItems var="branches" value="#{branchList}" noSelectionLabel="[Please Select]" label="#{branches.name}"/> <s:convertEntity /> <a4j:support event="onchange" reRender="section" focus="section" /> </h:selectOneMenu> <h:outputLabel for="section">Section</h:outputLabel> <h:selectOneMenu id="section" value="#{stud.masterSection}" > <s:selectItems var="sections" value="#{sectionList}" noSelectionLabel="[Please Select]" label="#{sections.section}"/> <s:convertEntity /> </h:selectOneMenu> <h:outputLabel for="session">Session</h:outputLabel> <h:selectOneMenu id="session" value="#{stud.masterSession}" > <s:selectItems var="sessions" value="#{sessionList}" noSelectionLabel="[Please Select]" label="#{sessions.acadYear}"/> <s:convertEntity /> </h:selectOneMenu> <h:outputLabel for="semester">Semester</h:outputLabel> <h:selectOneMenu id="semester" value="#{stud.masterSemester}" immediate="true" > <s:selectItems var="semesters" value="#{semesterList}" noSelectionLabel="[Please Select]" label="#{semesters.semester}"/> <s:convertEntity /> </h:selectOneMenu> <h:commandButton id="hello" label="Proceed" value="Proceed" action="/check.xhtml"> <s:conversationPropagation type="begin"/> </h:commandButton> </h:panelGrid> </h:form>
-
3. Re: Value not valid error
harsh4u89 Jul 5, 2010 4:41 AM (in response to harsh4u89)registrationBean.java
@Name("register") @Scope(ScopeType.CONVERSATION) public @Stateful class registrationBean implements registration,Serializable { /** * */ private static final long serialVersionUID = -1096164083206708820L; @In private EntityManager entityManager; @In(required=false) private StudentReg stud; @End public String doRegister() { entityManager.persist(stud); return "/home.xhtml"; } public String confirm() { return "/check.xhtml"; } @DataModel private List<MasterBranch> branchList; @Factory("branchList") public void initBranchList() { branchList = entityManager.createQuery("select p from MasterBranch p").getResultList(); } @DataModel private List<MasterSection> sectionList; @Factory("sectionList") public void initSectionList() { sectionList = entityManager.createQuery("select p from MasterSection p where p.masterBranch.id=#{stud.masterBranch.id}").getResultList(); } @DataModel private List<MasterSession> sessionList; @Factory("sessionList") public void initSessionList() { sessionList = entityManager.createQuery("select p from MasterSession p").getResultList(); } @DataModel private List<MasterSession> semesterList; @Factory("semesterList") public void initSemesterList() { semesterList = entityManager.createQuery("select p from MasterSemester p").getResultList(); } @Remove @Destroy public void destroy() { } }
-
4. Re: Value not valid error
harsh4u89 Jul 5, 2010 4:42 AM (in response to harsh4u89)MasterSection.java
@Entity @Name("masterSection") @Table(name = "master_section", catalog = "harsh1") public class MasterSection implements java.io.Serializable { /** * */ private static final long serialVersionUID = -1331030075760491783L; private Integer sectionId; private MasterBranch masterBranch; private String section; private Set<StudentReg> studentRegs = new HashSet<StudentReg>(0); private Set<StudentReg> studentRegs_1 = new HashSet<StudentReg>(0); public MasterSection() { } public MasterSection(MasterBranch masterBranch, String section) { this.masterBranch = masterBranch; this.section = section; } public MasterSection(MasterBranch masterBranch, String section, Set<StudentReg> studentRegs, Set<StudentReg> studentRegs_1) { this.masterBranch = masterBranch; this.section = section; this.studentRegs = studentRegs; this.studentRegs_1 = studentRegs_1; } @Id @GeneratedValue(strategy = IDENTITY) @Column(name = "Section_id", unique = true, nullable = false) public Integer getSectionId() { return this.sectionId; } public void setSectionId(Integer sectionId) { this.sectionId = sectionId; } @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "branch", nullable = false) @NotNull public MasterBranch getMasterBranch() { return this.masterBranch; } public void setMasterBranch(MasterBranch masterBranch) { this.masterBranch = masterBranch; } @Column(name = "Section", nullable = false, length = 5) @NotNull @Length(max = 5) public String getSection() { return this.section; } public void setSection(String section) { this.section = section; } @OneToMany(fetch = FetchType.LAZY, mappedBy = "masterSection") public Set<StudentReg> getStudentRegs() { return this.studentRegs; } public void setStudentRegs(Set<StudentReg> studentRegs) { this.studentRegs = studentRegs; } @OneToMany(fetch = FetchType.LAZY, mappedBy = "masterSection") public Set<StudentReg> getStudentRegs_1() { return this.studentRegs_1; } public void setStudentRegs_1(Set<StudentReg> studentRegs_1) { this.studentRegs_1 = studentRegs_1; } @Override public boolean equals(Object other) { return this.getSectionId().equals(((MasterSection) other).getSectionId()); } /*@BypassInterceptors @Override public int hashCode() { return this.getSectionId(); } */ }
-
5. Re: Value not valid error
harsh4u89 Jul 5, 2010 4:42 AM (in response to harsh4u89)The problem is coming in stud.masterSection field of the home.xhtml
-
6. Re: Value not valid error
harsh4u89 Jul 5, 2010 2:12 PM (in response to harsh4u89)Please tell me if there is any error in the code
-
7. Re: Value not valid error
lvdberg Jul 5, 2010 3:00 PM (in response to harsh4u89)Hi,
you didn't post the error, but I suspect that you're dealing with the famous null-pointer error, provoced by the ajax-request. You can prevent it by wrapping the ajax-part in a ajax-region. Something like the following:
<a4j:region > <h:selectOneListbox size="1" value="#{infraWebEditAction.inspector}" id="whoSelection"> <s:selectItems value="#{inspectorQuery}" var="_i" noSelectionLabel="Select" label="#{_i.alphabeticName}" /> <a4j:support event="onchange" ajaxSingle="true" bypassUpdates="false" eventsQueue="inputQueue" ignoreDupResponses="true" reRender="informEmail, informEmailLabel, informSms, informSmsLabel"/> <s:convertEntity /> </h:selectOneListbox> </a4j:region>
When you wrap it in the region, it will prevent the - what I call -leaking of the request to other parts of the page, When you don't prevent a number of jsf-components will submit a value although it's not in the part where your ajax-support is. It will lead to a submit of a null-value, which is not niocely handled by the converter, hence the error.
I found this solution helpful,
Leo
-
8. Re: Value not valid error
harsh4u89 Jul 6, 2010 12:56 PM (in response to harsh4u89)I tried but its not working
Value not valid error is coming...
Please suggest another solution
-
9. Re: Value not valid error
lvdberg Jul 6, 2010 2:32 PM (in response to harsh4u89)Hi,
have you tried the previous advice from craig.You implementation of equals and hascode is not really what it it should be. You could also try another component to check of that works.
Leo
-
10. Re: Value not valid error
harsh4u89 Jul 8, 2010 10:37 AM (in response to harsh4u89)What should be the correct implementation of the equals and hashcode ?????
-
11. Re: Value not valid error
harsh4u89 Jul 9, 2010 7:59 AM (in response to harsh4u89)Please help me solving this problem