Update components of a form in Primefaces

0

I am working on the validation of the fields of a form ("register new student").

If the form is empty as in the image and press on the register button, validate correctly and show the corresponding messages.

The problem is when I click on the button "New Student", the fields of the form are not updated and appear with a red color indicating that their fields are empty, when they should be completely white.

Note: Version of Primefaces 6.1

"New Student" Button Code

<h:form>
                <p:commandButton value="Nuevo Alumno/a" icon="ui-icon-plusthick" 
                                 update=":formNuevoAlumno"
                                 oncomplete="PF('dialogNuevoAlumno').show();"/>

            </h:form>

Form Code

<h:form id="formNuevoAlumno">
                <p:dialog id="dlgNuevoAlumno" header="Nuevo Alumno/a" widgetVar="dialogNuevoAlumno" 
                          resizable="false" showEffect="explode"
                          closable="true"
                          closeOnEscape="true"
                          hideEffect="explode" 
                          modal="true" 
                          style="min-width: 600px;min-height: 300px;">
                    <p:ajax onstart="#{participanteSecDataController.limpiar()}"
                            update=":formNuevoAlumno"
                            />
                    <p:separator/>
                    <p:panel header="Datos Personales" style="margin-bottom: 5px;">
                        <h:panelGrid id="pgDatosPersonales" columns="6" >
                            <h:outputLabel for="txtApellido" value="Apellido(s):"/>
                            <p:inputText id="txtApellido" 
                                         value="#{participanteSecDataController.persona.apellido}"
                                         required="true"
                                         />
                            <p:message for="txtApellido" display="icon"/>
                            <h:outputLabel value="Nombre(s):"/>
                            <p:inputText id="txtNombre" value="#{participanteSecDataController.persona.nombre}" />
                            <p:message for="txtNombre" display="icon"/>
                            <h:outputLabel value="D.N.I.:"/>
                            <p:inputText id="txtDNI" value="#{participanteSecDataController.persona.nroDoc}"/>
                            <p:message for="txtDNI" display="icon"/>
                            <h:outputLabel value="Teléfono:"/>
                            <p:inputText id="txtTelefono" value="#{participanteSecDataController.persona.telefono}"/>
                            <p:message for="txtTelefono" display="icon"/>
                            <h:outputLabel value="Email:"/>
                            <p:inputText id="txtEmail" value="#{participanteSecDataController.persona.email}" />
                            <p:message for="txtEmail" display="icon"/>
                            <h:outputLabel for="sorSexo" value="Sexo:"/>
                            <p:selectOneRadio id="sorSexo" value="#{participanteSecDataController.persona.sexo}"  
                                              converter="javax.faces.Integer">
                                <f:selectItem itemLabel="M" itemValue="2" />
                                <f:selectItem itemLabel="F" itemValue="1" />
                            </p:selectOneRadio>
                            <p:message for="sorSexo" display="icon" id="msjSexo"/>
                        </h:panelGrid>
                    </p:panel>
                    <p:panel header="Datos Académicos" style="margin-bottom: 2px;">
                        <h:panelGrid columns="2" cellspacing="5">
                            <h:outputLabel for="somF" value="Establecimiento Educativo: "/>
                            <p:selectOneMenu id="somF" value="#{participanteSecDataController.establecimiento.idEstablecimiento}" 
                                             converter="javax.faces.Integer"
                                             required="true"
                                             effect="fold"
                                             requiredMessage="Debe seleccionar un tipo de documento"
                                             filter="true"
                                             filterMatchMode="contains">
                                <f:selectItem itemLabel="Seleccionar" noSelectionOption="true"/>
                                <f:selectItems value="#{actividadDataController.listaEstablecimiento}"
                                               var="f" itemLabel="#{f.descripcion}"
                                               itemValue="#{f.idEstablecimiento}"/>
                            </p:selectOneMenu>
                        </h:panelGrid>
                    </p:panel>
                    <p:separator/>
                    <h:panelGrid columns="2" style="float: right;">
                        <p:commandButton value="Registrar" 
                                         icon="ui-icon-check"
                                         actionListener="#{participanteSecDataController.registrar()}" 
                                         update=":formNuevoAlumno:pgDatosPersonales,
                                         :formMostrarAlumnos:tablaAlumnos,
                                         :formMostrarAlumnos:msgs" 
                                         />
                        <p:commandButton value="Cancelar" 
                                         icon="ui-icon-closethick"
                                         process="@this"

                                         oncomplete="PF('dialogNuevoAlumno').hide();"/>
                    </h:panelGrid>
                </p:dialog>
            </h:form>

    
asked by francisco castillo 30.04.2018 в 23:39
source

1 answer

0

When you give the new student, what you have to do is enter your controller and create a method () that cleans each value, this is done by setting each attribute of your form and I think it would be better than when you want to validate do it from your controller because I have given me problems when I validate from the view and nothing else you send a FacessMessages.

    
answered by 17.05.2018 в 23:17