I have 2 generic templates for crud . (% 2) The search for the template CRUD . XHTML (Code 2) has the following logic: (When you open the page, all input fields are disabled when you click the first time on the Search button, it enables all fields, if I click again without filling any fields, it searches all the records of my object, if any or all fields are filled it searches the records according to the field data) .
I have the following problem: To validate the data at save time, I am using the commandButton
annotation, so at the time I click the search button and I do not report anything in my inputText description it does validation. To get around this behavior, I made use of **@NotNull**
in my process=@this
search, but I got a new problem. Using commandButton
in the component process=@this
search, it is not considering the information populated in the inputText component of my screen, so when clicking the search button, it is always searched for all the data. To solve this problem (With a great help from friend Rafael in another post [insert link description here] [1]), I left my commandButton with *commandButton*
and in my inputText description I used *process=@this*
and is working properly.
But I noticed that I will have to insert this event ajax in all the fields of all the screens that will use this template, so I am trying to use process in my < search of my tamper CRUD.XHTML (Code 2) as follows p:ajax event="change" process="@this"
and is not working because it is falling into validation.
If anyone knows how to circumvent this situation and can help.
Page Codes!
Template CRUD basic.xhtml (Code 1)
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:h="http://java.sun.com/jsf/html" xmlns:f="http://java.sun.com/jsf/core" xmlns:p="http://primefaces.org/ui">
<h:head>
<title>${titulo}</title>
<h:outputStylesheet name="core.js" target="head" library="js" />
<h:outputStylesheet name="style.css" target="head" library="css" />
</h:head>
<h:body>
<div id="dvStatus" align="center">
<p:ajaxStatus onstart="PF('statusDialog').show();" onsuccess="PF('statusDialog').hide();" />
<p:dialog modal="true" widgetVar="statusDialog" draggable="false" closable="false" resizable="false" showHeader="false">
<p:graphicImage value="/resources/img/icon/ajaxloading3.gif" />
</p:dialog>
</div>
<h:form id="formCrud">
<ui:insert name="cabecalho">
<ui:include src="tmenu.xhtml" />
</ui:insert>
<p:toolbar/>
<ui:insert name="toolbar">
<p:toolbar id="tool">
<p:toolbarGroup>
<ui:insert name="toolbarButtons" />
</p:toolbarGroup>
</p:toolbar>
</ui:insert>
<ui:insert name="panelExterno">
<ui:insert name="panelCentral" />
<center>
<h:messages id="growl" showDetail="true" autoUpdate="true" closable="true" showSummary="false" errorClass="converterMsgError" warnClass="converterMsgWarn" infoClass="converterMsgInfo" fatalClass="converterMsgError" />
</center>
</ui:insert>
<p:confirmDialog global="true">
<p:commandButton value="Sim" type="button" styleClass="ui-confirmdialog-yes" icon="confirm" />
<p:commandButton value="Não" type="button" styleClass="ui-confirmdialog-no" icon="cancel" />
</p:confirmDialog>
</h:form>
</h:body>
</html>
Template CRUD CRUD.xhtml (Code 2)
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns="http://www.w3.org/1999/xhtml" xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:f="http://java.sun.com/jsf/core" xmlns:h="http://java.sun.com/jsf/html" xmlns:p="http://primefaces.org/ui" template="/templates/basic.xhtml">
<ui:define name="toolbarButtons">
<ui:insert name="btnNew">
<p:commandButton id="new" value="Novo" actionListener="#{backingBean.novo}" update="tool pnlCampos growl" disabled="#{backingBean.disableBtnNew}" icon="novo" style="width:100px; margin-left: 6px;" />
</ui:insert>
<ui:insert name="btnSave">
<p:commandButton id="save" value="Salvar" actionListener="#{backingBean.salvar}" update="tool pnlCampos pnlTable growl" disabled="#{backingBean.disableBtnSave}" icon="gravar" style="width:100px;margin-left: 6px;" />
</ui:insert>
<ui:insert name="btnCancel">
<p:commandButton id="cancel" value="Cancelar" actionListener="#{backingBean.cancelar}" process="@this" update="tool pnlCampos pnlTable growl" disabled="#{backingBean.disableBtnCancel}" icon="cancel" style="width:100px;margin-left: 6px;" />
</ui:insert>
<ui:insert name="btnFind">
<p:commandButton id="search" value="Pesquisar" actionListener="#{backingBean.pesquisar}" process="@this pnlCampos" update="tool pnlCampos pnlTable growl" disabled="#{backingBean.disableBtnSearch}" icon="search" style="width:100px;margin-left: 6px;" />
</ui:insert>
<ui:insert name="btnExport" />
<ui:insert name="toolbarExtraButtons" />
</ui:define>
<ui:define name="panelCentral">
<ui:insert name="panelDeCadastro">
<p:panel id="pnlCampos" header="${toolTitulo}">
<ui:insert name="panelCadastro" />
</p:panel>
</ui:insert>
<ui:insert name="table">
<p:outputPanel id="pnlTable" deferred="true">
<p:dataTable id="table" value="#{backingBean.model}" var="obj" rows="8" paginator="true" paginatorPosition="bottom" emptyMessage="" rowStyleClass="#{empty rowIx or rowIx mod 2 ne 0 ? 'even-row' : 'odd-row'}" rowIndexVar="rowIx" scrollable="true">
<f:facet name="header">
Registro(s) Cadastrado(s)
</f:facet>
<ui:insert name="colunasTabela" />
<p:column id="edit" style="width: 10px; text-align:center;">
<p:commandLink title="Editar Registro" actionListener="#{backingBean.editar}" process="@this" update=":formCrud:pnlCampos :formCrud:tool :formCrud:pnlTable :formCrud:growl">
<p:graphicImage value="/resources/img/icon/editar_16x16.png" />
</p:commandLink>
</p:column>
<p:column id="del" style="width: 10px; text-align:center;">
<p:commandLink title="Deletar Registro" actionListener="#{backingBean.excluir}" process="@this" update=":formCrud:pnlCampos :formCrud:tool :formCrud:pnlTable :formCrud:growl">
<p:graphicImage value="/resources/img/icon/excluir_16x16.png" />
<f:setPropertyActionListener target="#{backingBean.rowData}" value="#{obj}" />
<p:confirm header="Atenção" message="Você confirma a exclusão desse registro ?" icon="ui-icon-alert" />
</p:commandLink>
</p:column>
</p:dataTable>
</p:outputPanel>
</ui:insert>
</ui:define>
</ui:composition>
Job Title Screen (Code 3)
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:f="http://java.sun.com/jsf/core" xmlns:h="http://java.sun.com/jsf/html" xmlns:p="http://primefaces.org/ui">
<ui:composition template="/templates/crud.xhtml">
<ui:param name="titulo" value="Tela de Cargo" />
<ui:param name="toolTitulo" value="Cadastro e Edição de Cargo" />
<ui:param name="backingBean" value="#{cargoBean}" />
<ui:define name="panelCadastro">
<h:panelGrid id="pnlGrdCargo" columns="1" width="100%">
<h:outputText value="Descrição:" />
<p:inputText value="#{cargoBean.domain.descricao}" onkeyup="this.value = this.value.toUpperCase()" disabled="#{cargoBean.disabledOnDefault}" style="width: 30%;" />
</h:panelGrid>
</ui:define>
<ui:define name="colunasTabela">
<p:column headerText="Código" style="width: 50px;">
<h:outputText value="#{obj.codigoCargoFuncionario}" />
</p:column>
<p:column headerText="Descrição">
<h:outputText value="#{obj.descricao}" />
</p:column>
</ui:define>
</ui:composition>
</html>
Thank you!