0

I've been working with PrimeFaces for less than 24 hours so maybe I'm missing the obvious.

I have two SelectOneMenu components. the second one is no rendered at first. When a value is changed in the first one. the listener retrieves data from db, update ManagedBean property with the data and change boolean property to show the second one. The second Menu is now rendered but no data is shown.

Here is the snippet:

<h:form prependId="false" id="notaForm">
        <h:panelGrid>
            <p:selectOneMenu value="#{notaBean.idCurso}" 
                style="width:150px" >
                <f:selectItem itemLabel="Seleccione curso" itemValue="" noSelectionOption="true" />
                <f:selectItems value="#{notaBean.cursos}" var="c" itemLabel="#{c.nombre}" itemValue="#{c.idCurso}"/>
                <p:ajax event="change" listener="#{notaBean.onSelectCurso}" update="alumno" />
            </p:selectOneMenu>
        </h:panelGrid>

        <h:panelGrid id="alumno">
            <p:selectOneMenu value="#{notaBean.idAlumno}" var=""
                style="width:150px" rendered="#{notaBean.mostrarAlumnos}">
                <f:selectItem itemLabel="Seleccione alumno" itemValue="" noSelectionOption="true" />
                <f:selectItems value="#{notaBean.alumnos}" var="a" itemLabel="#{a.nombre}" itemValue="#{a.idAlumno}"/>
                <p:ajax event="change" listener="#{notaBean.onSelectAlumno}" update="nota" />
            </p:selectOneMenu>
        </h:panelGrid>

        <h:panelGrid id="nota">
            <p:outputLabel for="nota" value=""
                rendered="#{notaBean.mostrarNota}" />
            <p:inputText value="#{notaBean.nota}" label="nota"
                rendered="#{notaBean.mostrarNota}" />

            <h:commandButton action="#{notaBean.insertarNota()}" id="button"
                value="Guardar nota" rendered="#{notaBean.mostrarNota}"/>
        </h:panelGrid>

    </h:form>

notaBean.alumnos has a size of 2 (it recovers both alumni from db), and the properties nombre and idAlumno shows correctly when I print them out in console.

barych
  • 3
  • 4
  • 1
    Don't use [prependId="false"](http://stackoverflow.com/questions/7415230/uiform-with-prependid-false-breaks-fajax-render) (ever). And I think the norm would be to bind the selectOneMenu's to an instance of the object (i.e. Curso), not the id (which I think you do?). You'd then use itemValue="#{c}" and have a converter to automatically convert between id and instance. The prependId might solve the problem, the last is just more JSF-like – Jaqen H'ghar Apr 30 '16 at 12:41
  • I didn't know about prepenId bad practice. I deleted it. Well, there was in the code a var="" that was causing the problem. I must have left it there while trying things. Without it the second Menu gets the data. But the listener bound to its onSelect won't get called. Does it have to do with not being rendered the first time and doing it only with an ajax update?? – barych Apr 30 '16 at 16:10
  • Solved. I wasn't giving it a View scoped and that was causing the no invocation of listeners. – barych May 01 '16 at 12:42

0 Answers0