Two selectOneMenu in a page and action from one to other

Advertisement

Two selectOneMenu in a page and action from one to other
Hi everybody. I have two selectOneMenu in a jsf page. In the fist there is a list of students, and in the second there is a list of courses. I want, when I select a student, to launch a methot that show me in the second selectOneMenu only the courses that the studend is enrolled. Because I new on Jsf, I think to use the onClick property, but I don't know how I can use it. I don't use AJAX, so I must reload all the page. There is any other way to do this? Thanks to all.
Repaly
Thanks, I use it, and now I have this jsf page:
<h:selectOneMenu id="lista_studenti" binding="#{svolgiSingoloEsercizioBean.menuStudenti}" onchange="this.form.submit();" valueChangeListener="#{svolgiSingoloEsercizioBean.studenteSelezionato}" immediate="true">
          <f:selectItems id="studente" value="#{svolgiSingoloEsercizioBean.studenti}" />
</h:selectOneMenu>
<f:verbatim>
</f:verbatim>
<h:selectOneMenu id="lista_corsi" binding="#{svolgiSingoloEsercizioBean.menuCorsi}" onchange="this.form.submit();" valueChangeListener="#{svolgiSingoloEsercizioBean.corsoSelezionato}" immediate="true" rendered="#{svolgiSingoloEsercizioBean.menuStudenti.value != null}">
          <f:selectItems id="corso" value="#{svolgiSingoloEsercizioBean.corsi}" />
</h:selectOneMenu>
<f:verbatim>
</f:verbatim>
<h:selectOneMenu id="lista_esercizi" binding="#{svolgiSingoloEsercizioBean.menuEsercizi}" rendered="#{svolgiSingoloEsercizioBean.menuCorsi.value != null}" >
          <f:selectItems id="esercizio" value="#{svolgiSingoloEsercizioBean.esercizi}" />
</h:selectOneMenu>
When I change the second selectOneMenu, I have this error:
type Exception report
message
description The server encountered an internal error () that prevented it from fulfilling this request.
exception
javax.servlet.ServletException: Value binding '#{svolgiSingoloEsercizioBean.corsi}'of UISelectItems with component-path {Component-Path : [Class: javax.faces.component.UIViewRoot,ViewId: /cercaesercizi_studentecorso.jsp][Class: javax.faces.component.html.HtmlForm,Id: _idJsp0][Class: javax.faces.component.html.HtmlSelectOneMenu,Id: lista_corsi][Class: javax.faces.component.UISelectItems,Id: corso]} does not reference an Object of type SelectItem, SelectItem[], Collection or Map but of type : null
     javax.faces.webapp.FacesServlet.service(FacesServlet.java:152)
root cause
java.lang.IllegalArgumentException: Value binding '#{svolgiSingoloEsercizioBean.corsi}'of UISelectItems with component-path {Component-Path : [Class: javax.faces.component.UIViewRoot,ViewId: /cercaesercizi_studentecorso.jsp][Class: javax.faces.component.html.HtmlForm,Id: _idJsp0][Class: javax.faces.component.html.HtmlSelectOneMenu,Id: lista_corsi][Class: javax.faces.component.UISelectItems,Id: corso]} does not reference an Object of type SelectItem, SelectItem[], Collection or Map but of type : null
     javax.faces.component._SelectItemsIterator.hasNext(_SelectItemsIterator.java:131)
     javax.faces.component._SelectItemsUtil.matchValue(_SelectItemsUtil.java:46)
     javax.faces.component.UISelectOne.validateValue(UISelectOne.java:62)
     javax.faces.component.UIInput.validate(UIInput.java:353)
     javax.faces.component.UIInput.processDecodes(UIInput.java:158)
     javax.faces.component.UIForm.processDecodes(UIForm.java:53)
     javax.faces.component.UIComponentBase.processDecodes(UIComponentBase.java:602)
     javax.faces.component.UIViewRoot.processDecodes(UIViewRoot.java:135)
     org.apache.myfaces.lifecycle.LifecycleImpl.applyRequestValues(LifecycleImpl.java:219)
     org.apache.myfaces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:71)
     javax.faces.webapp.FacesServlet.service(FacesServlet.java:137)
Is because I don't use the converter?
Read More: The other 7 answers