Custom Roweditor

1

Greetings. I have the following problem Given the following view:

client.xhtml

    <p:fieldset>
        <p:fieldset legend="Informacion Personal del Cliente">
            <h:panelGrid id="panelCliente"
                         columns="6" 
                         columnClasses="headerColPanelGrid, 
                         valueColPanelGrid, 
                         errorColPanelGrid,
                         headerColPanelGrid, 
                         valueColPanelGrid, 
                         errorColPanelGrid"
                         >                 
                <p:outputLabel for="txtClienteNombres" 
                               value="Nombres *"/>
                <p:inputText id="txtClienteNombres" 
                             required="false" 
                             class="textBoxWidth100"
                             value="#{clienteController.cliente.nombres}"
                             placeholder="Ingrese Nombres"
                             immediate="false"
                             validator="clienteValidator"
                             converter="soloTextoV1Converter"
                             >
                </p:inputText>
                <p:message for="txtClienteNombres"/>

                <p:outputLabel for="txtClienteApellidos" 
                               value="Apellidos *"/>
                <p:inputText id="txtClienteApellidos" 
                             required="false" 
                             class="textBoxWidth100" 
                             value="#{clienteController.cliente.apellidos}"
                             placeholder="Ingrese Apellidos"
                             immediate="false"
                             validator="clienteValidator"
                             converter="soloTextoV1Converter"
                             >
                </p:inputText>
            </h:panelGrid>    

        <p:commandButton id="cmdClienteReservar"
                         actionListener="#{clienteController.saveTmp()}" 
                         value="Reservar"
                         update="@parent"
                         immediate="false"
                         >
        </p:commandButton>
        <p:commandButton  id="cmdClienteCrear"
                          actionListener="#{clienteController.createCliente()}" 
                          value="Crear" 
                          update="@parent"
                          rendered="#{clienteController.cliente.id lt 0}"
                          onstart="PF('BUI').show()" 
                          oncomplete="PF('BUI').hide()"
                          >     
            <f:param name="paramValidate" value="true" />
            <f:param name="paramTipoIdent" value="#{clienteController.cliente.tipoIdentificacion}" />
        </p:commandButton>
        <p:commandButton  id="cmdClienteEditar"
                          actionListener="#{clienteController.editCliente()}" 
                          value="Editar" 
                          update="@parent"
                          rendered="#{clienteController.cliente.id gt 0}"
                          onstart="PF('BUI').show()" 
                          oncomplete="PF('BUI').hide()"
                          >
            <f:param name="paramValidate" value="true" />
            <f:param name="paramTipoIdent" value="#{clienteController.cliente.tipoIdentificacion}" />
        </p:commandButton>
    </p:fieldset>

It contains a validator that receives a paramValidate parameter, the same one that will only validate when the Create or Edit events are to later save them in the database. And in the Reserve event, it allows me to temporarily save the data in an array without the need to validate.

CustomerValidator

    @FacesValidator
    public class ClienteValidator implements Validator {

        @Override
        public void validate(FacesContext context, UIComponent component, Object value) throws ValidatorException {
            if (!continueValidacion()) {
                return;
            }

            FacesMessage fm;
            String comp = (String) component.getId();
            String valor;
            Date valorFecha;

            ...........

        }

        protected boolean continueValidacion() {
            String skipValidator = FacesContext.getCurrentInstance().
                    getExternalContext().getRequestParameterMap().get("paramValidate");
            return (skipValidator != null && skipValidator.equalsIgnoreCase("true"));
        }

    }

Now I need to raise the same schema but for a datatable, but the problem is that the roweditor components do not allow passing parameters.

contacts.xhtml

                                                                                 

                <c:if test="#{clienteController.cliente.id > 0}">
                    <f:facet name="header">
                        <p:outputPanel style="text-align: right;">
                            <p:commandButton value="Nuevo Contacto" 
                                             actionListener="#{clienteController.onRowAddContacto}"
                                             update="dataTableContacto" />
                        </p:outputPanel>
                        <p:outputPanel style="text-align: right;">
                            <p:commandButton value="Editar Contacto" 
                                             actionListener="#{clienteController.onRowEditContacto}"
                                             update="dataTableContacto" />
                        </p:outputPanel>
                    </f:facet>
                </c:if>                    

                <p:column id="colContactoId" 
                          headerText="Id"
                          visible="true">     
                    <p:cellEditor>
                        <f:facet name="output">
                            <h:outputText value="#{contacto.id}"
                                          />
                        </f:facet>
                        <f:facet name="input">
                            <p:inputText id="txtContactoId" 
                                         readonly="true"
                                         value="#{contacto.id}"/>
                        </f:facet>
                    </p:cellEditor>
                </p:column>

                <p:column id="colContactoTipo" 
                          headerText="Tipo Contacto">
                    <p:cellEditor>
                        <f:facet name="output">
                            <h:outputText value="#{globalController.getEtiquetaContactoTipos(contacto.tipoContacto)}"/>
                        </f:facet>
                        <f:facet name="input">
                            <p:selectOneMenu id="cmbContactoTipo" 
                                             required="false"
                                             value="#{contacto.tipoContacto}"
                                             style="width: 90%"
                                             placeholder="Tipo de Contacto"
                                             immediate="false"
                                             validator="contactoValidator"
                                             >
                                <f:selectItem itemValue="#{null}" 
                                              itemLabel="--Seleccione--" />
                                <f:selectItems value="#{globalController.comboContactoTipos}" />
                            </p:selectOneMenu>
                        </f:facet>
                    </p:cellEditor>
                </p:column>

                <p:column id="colContactoValor" 
                          headerText="Descripcion">
                    <p:cellEditor>
                        <f:facet name="output">
                            <h:outputText value="#{contacto.valor}"
                                          class="textBoxWidth100"/>
                        </f:facet>
                        <f:facet name="input">
                            <p:inputText id="txtContactoValor" 
                                         value="#{contacto.valor}" 
                                         class="textBoxWidth100"
                                         placeholder="Descripcion del Contacto"
                                         immediate="false"
                                         validator="contactoValidator"
                                         converter="soloTextoNumeroV3Converter"
                                         >
                            </p:inputText>
                        </f:facet>
                    </p:cellEditor>
                </p:column>

                <p:column id="colContactoEstado" 
                          headerText="Estado">
                    <h:outputText value="#{globalController.getEtiquetaGeneralEstados(contactos.estado)}"/>
                </p:column>

                <p:column id="colContactoFecCreacion" 
                          headerText="Fec. Creacion" >
                    <h:outputText value="#{contacto.fechaCreacion}">
                        <f:convertDateTime pattern="dd/MM/yyyy HH:mm:ss" />
                    </h:outputText>
                </p:column>

                <p:column id="colContactoEditor"
                            style="width: 50px"
                          headerText="Editar">
                    <p:rowEditor id="cmdContactoEditar">
                        <f:param name="paramValidate" value="true" />
                    </p:rowEditor>
                </p:column>

            </p:dataTable>

validateContact

    @FacesValidator
    public class ContactoValidator implements Validator {

        @Override
        public void validate(FacesContext context, UIComponent component, Object value) throws ValidatorException {
            if (!continueValidacion()) {
                return;
            }

            FacesMessage fm;
            String comp = (String) component.getId();
            String valor;

            .....
        }

        protected boolean continueValidacion() {
            String skipValidator = FacesContext.getCurrentInstance().
                    getExternalContext().getRequestParameterMap().get("paramValidate");
            return (skipValidator != null && skipValidator.equalsIgnoreCase("true"));
        }

    }

The question is. How could you pass the paramValidate parameter inside the roweditor , or how could you simulate the functionality of the edit / cancel of the datatable with buttons to send this parameter in this way?

Thanks

    
asked by Fernando Ortega 08.09.2017 в 07:00
source

0 answers