开发者

jsf page throws j_idt9:stud: Validation Error: Value is not valid [duplicate]

This question already has answers here: Validation Error: Value is not valid 开发者_如何学编程 (3 answers) Closed 6 years ago.

This is the listbox in my jsfpage:

<h:selectOneListbox id="stud" value="#{inschrijven.student.studentnr}">
                <f:selectItems value="#{inschrijven.gezochteStudenten}" var="st" itemLabel="#{st.studentnr}" itemValue="#{st.studentnr}"/></h:selectOneListbox>

in my managedBean Inschrijven.java:

private Student student;
    private List<Student> gezochteStudenten;

in my constructor I make the student attribute:

student = new Student();

so first I search students => gezochteStudenten this works, I debugged and it worked like it should...

But when I click the button "schrijfin" it gives an exception and it won't even go to my method: j_idt9:stud: Validation Error: Value is not valid

any idea how this is possible and how i can fix this?

the property studentnr is at both sides of the type "String" so this won't be the problem...


During the validations phase of the form submit request, JSF will basically re-iterate over the select item values and compare the submitted value against it using Object#equals() method. If the submitted value doesn't match any of the select item values, then you'll get this validation error.

In your particular case, this validation error suggests that the #{inschrijven.gezochteStudenten}" didn't return exactly the same list during processing the form submit request as it did during displaying the form. This in turn suggests that your #{inschrijven} managed bean is request scoped and that the property gezochteStudenten is not populated during bean's (post)construction, but rather during some event method of the previous action. A request scoped bean is garbaged when the response is finished and a brand new one is constructed during the form submit request.

There are several ways to solve this problem, which depends on the JSF spec version you're using and the available comopnent libraries. You didn't mention/tag the JSF spec version used in your question, but your <f:selectItems> declaration hints that you're using JSF 2.x (the var attribute was introduced in JSF 2.0), so you could take benefit of the new JSF 2.0 view scope. If you put the #{inschrijven} managed bean in the view scope, this problem should be solved. The same bean will then be used during processing the form submit as during displaying the form.

@ManagedBean
@ViewScoped
public class Inschrijven {
    // ...
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜