Bean Validation Tela Cadastro e Pesquisa

10 respostas
java
jeroqueiroz

Possuo uma tela onde a mesma e cadastro e pesquisa, onde os campos estão sendo validados com Bean Validation, porem gostaria que quando fosse acionado o botão gravar efetuasse a validação como já esta, mas quando fosse acionado o botão pesquisar a mesma permitisse a pesquisa sem a obrigatoriedade dos campos que são obrigatórios para o cadastro.

Obrigado desde já!

10 Respostas

Marcus_Gp

Acredito que a tecnologia que você está usando seja JSF. Portanto tente colocar a propriedade process="@this" no seu commandButton, que ele irá processar somente o botão.

jeroqueiroz

O @this no botão não funcionou. Ele envia somente o próprio botão e os valores dos campos não são enviados.

Alguma sugestão?

Marcus_Gp

Altere, além de @this, coloce os IDs dos campos que você precisa processar para a pesquisar funcionar. Se não souber como fazer, só jogar no google que tem muita coisa explicando sobre o process

jeroqueiroz

Acho que não compreendeu meu problema.

Vou testar esta solução:

Mateus_Malaquias1

Mostra o código do teu xhtml

jeroqueiroz

`
< ui:composition xmlns=“http://www.w3.org/1999/xhtml” xmlns:h=“http://java.sun.com/jsf/html"
xmlns:f=“http://java.sun.com/jsf/core” xmlns:ui=“http://java.sun.com/jsf/facelets” xmlns:p=“http://primefaces.org/ui"
template=”/WEB-INF/template/template.xhtml”>

<ui:define name="content">  
    <div class="ContainerIndent">  
        <p:panel>  
            <div class="ContainerIndent">  
                <h:outputText value="Tipo de Documento" styleClass="FontBold Fs18 hardblue" />  

                <f:metadata>  
                    <f:viewParam name="dummy" />  
                    <f:event listener="#{documentTypeBean.initialize()}" type="preRenderView" />  
                </f:metadata>  

                <h:form id="formDocumentType">  

                    <p:inputText id="id" type="hidden" value="#{documentTypeBean.documentType.id}" />  

                    <p:messages id="msgValidation" autoUpdate="true" closable="true" />  

                    <div class="EmptyBox10"></div>  
                    <p:panelGrid columns="2" style="width: 100%;">  

                        <p:outputLabel value="Descrição" for="description" />  
                        <p:inputText id="description" size="50" maxlength="50" styleClass="Wid90"  
                            value="#{documentTypeBean.documentType.description}" />  

                        <p:outputLabel value="Sigla" for="initials" />  
                        <p:inputMask id="initials" styleClass="Wid20" size="5" maxlength="5"  
                            value="#{documentTypeBean.documentType.initials}" />  

                        <p:outputLabel value="Documento Ativo" for="ativo" />  
                        <p:selectBooleanCheckbox id="ativo" value="#{documentTypeBean.documentType.status}" />  
                    </p:panelGrid>  

                    <div class="EmptyBox20"></div>  
                    <p:toolbar>  
                        <f:facet name="right">  
                            <p:commandButton value="Pesquisar" styleClass="OrangeButton" action="#{documentTypeBean.findByFilter()}"  
                                update="formListDocumentType:gridDocumentType formDocumentType" />  

                            <p:commandButton value="Cancelar" styleClass="RedButton" action="#{documentTypeBean.clear()}" update="@form" />  

                            <p:commandButton value="Salvar" styleClass="GreenButton" action="#{documentTypeBean.save()}"  
                                update="formListDocumentType:gridDocumentType formDocumentType" />  
                        </f:facet>  
                    </p:toolbar>  

                    <div class="EmptyBox20"></div>  
                </h:form>  

                <h:form id="formListDocumentType">  
                    <p:dataTable id="gridDocumentType" value="#{documentTypeBean.documentsTypes}" var="documentType" rows="5"  
                        paginator="true" paginatorAlwaysVisible="false" paginatorPosition="bottom"  
                        paginatorTemplate="{CurrentPageReport}  {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"  
                        emptyMessage="Nenhum Tipo de Documento Encontrado." reflow="true" resizableColumns="true">  
                        <!-- rowsPerPageTemplate="5,10,15" -->  

                        <f:facet name="header">Tipo de Documentos</f:facet>  

                        <p:column headerText="Descrição" sortBy="#{tipoDocumento.description}">  
                            <h:outputText value="#{documentType.description}" />  
                        </p:column>  

                        <p:column headerText="Sigla" sortBy="#{tipoDocumento.initials}">  
                            <h:outputText value="#{documentType.initials}" />  
                        </p:column>  

                        <p:column headerText="Status" sortBy="#{tipoDocumento.ativo}">  
                            <h:outputText value="Habilitado" rendered="#{documentType.status}" />  
                            <h:outputText value="Desabilitado" rendered="#{!documentType.status}" />  
                        </p:column>  


                        <p:column style="width:70px;" headerText="Ações">  
                            <p:commandButton styleClass="BlueButton" icon="fa fa-edit Fs16 white" update="formDocumentType">  
                                <f:setPropertyActionListener target="#{documentTypeBean.documentType}" value="#{documentType}" />  
                            </p:commandButton>  

                            <p:commandButton styleClass="RedButton" icon="fa fa-remove Fs16 white"  
                                oncomplete="PF('exclusionConfirmation').show();" process="@this"  
                                update=":formListDocumentType:exclusionConfirmationDialog">  
                                <f:setPropertyActionListener target="#{documentTypeBean.documentTypeSelected}" value="#{documentType}" />  
                            </p:commandButton>  
                        </p:column>  
                    </p:dataTable>  

                    <p:confirmDialog id="exclusionConfirmationDialog" widgetVar="exclusionConfirmation"  
                        message="Tem certeza que deseja excluir #{documentTypeBean.documentTypeSelected.description}?"  
                        header="Exclusão Tipo de Documento" showEffect="fade" hideEffect="fade">  

                        <p:commandButton value="Não" styleClass="ui-confirmdialog-no" icon="ui-icon-close fa fa-close Fs14 white"  
                            onclick="PF('exclusionConfirmation').hide(); return false;" />  

                        <p:commandButton value="Sim" styleClass="ui-confirmdialog-yes" icon="ui-icon-check fa fa-check Fs14 white"  
                            oncomplete="PF('exclusionConfirmation').hide();" action="#{documentTypeBean.remove()}"  
                            update=":formListDocumentType:gridDocumentType" type="submit" />  
                    </p:confirmDialog>  
                </h:form>  
            </div>  
        </p:panel>  

        <div class="EmptyBox20"></div>  
    </div>  
</ui:define>

</ui:composition> `

Mateus_Malaquias1

Quais inputs o botão pesquisar deve processar para enviar o valor pro bean?

jeroqueiroz

Os dois Campos de Sigla e Pesquisa.

Vi esta opção, mas ainda vou testar.

Mateus_Malaquias1

colocou o param, isso vai funcionar sim :slight_smile:

jeroqueiroz

Vou testar a noite. Qualquer problema volto a postar. Obrigado a atenção.

Criado 5 de julho de 2016
Ultima resposta 7 de jul. de 2016
Respostas 10
Participantes 3