我正在使用带有Primefaces 4的JSF,我有一个带tabPanel的crud,我想在点击保存按钮时只处理几个字段,所以我用ah:panelGroup包含带有id的字段并添加进程attributte to my p:commandButton。有代码:
当我使用facelets定义模板时,我将从头开始发布:
我的crudTemplate.xhtml
<ui:composition template="/WEB-INF/template/sistema.xhtml"
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">
<ui:define name="conteudo">
<ui:insert name="cabecalho">
<ui:include src="/WEB-INF/template/componentes/titulo.xhtml"/>
</ui:insert>
<ui:insert name="corpo">
<p:growl id="growl" autoUpdate="true" sticky="true" globalOnly="true"/>
<div class="row">
<div class="col-md-12">
<div class="box border primary">
<div class="box-title">
<h4>#{tituloCorpo}</h4>
</div>
<ui:insert name="areaTabs">
<div class="box-body">
<div class="tabbable header-tabs">
<ul class="nav nav-tabs">
<ui:insert name="tabPesquisa">
<li><a href="#box_tab_pesquisa"
data-toggle="tab" accesskey="p"><i
class="fa fa-search"></i> <span
class="hidden-inline-mobile"><u>P</u>esquisar</span> </a></li>
</ui:insert>
<ui:insert name="tabCadastro">
<li class="active"><a href="#box_tab_cadastro" data-toggle="tab"
accesskey="c"><i class="fa fa-tasks"></i> <span
class="hidden-inline-mobile"><u>C</u>adastrar</span> </a></li>
</ui:insert>
</ul>
<div class="tab-content">
<div id="box_tab_cadastro" class="tab-pane fade in active">
<h:panelGroup id="panelContentCadastro" layout="block">
<ui:insert name="conteudoTabCadastro">
<ui:include src="/WEB-INF/template/cadastro/areaCadastro.xhtml"/>
</ui:insert>
</h:panelGroup>
</div>
<div id="box_tab_pesquisa" class="tab-pane fade">
<h:panelGroup id="panelContentPesquisa" layout="block">
<ui:insert name="conteudoTabPesquisa">
<ui:include src="/WEB-INF/template/pesquisa/areaPesquisa.xhtml"/>
</ui:insert>
</h:panelGroup>
</div>
</div>
</div>
</div>
</ui:insert>
<ui:insert name="dialogsAdicionais"/>
</div>
</div>
</div>
</ui:insert>
</ui:define>
这是具体的问题:
<ui:composition template="/WEB-INF/template/crudTemplate.xhtml"
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:o="http://omnifaces.org/ui"
xmlns:of="http://omnifaces.org/functions"
xmlns:p="http://primefaces.org/ui"
xmlns:max="http://java.sun.com/jsf/composite/tags">
<ui:param name="tituloCabecalho" value="Cadastro de Clientes Software House" />
<ui:param name="descricaoCabecalho" value="Cadastre, Pesquisa, Altere e Exclua Clientes Software House" />
<ui:param name="tituloCorpo" value="Clientes Software House" />
<ui:param name="controller" value="#{clienteSoftwareHouseController}"/>
<ui:define name="conteudoTabCadastro">
<h:panelGroup id="panelGroupCadastro" layout="block">
<h:form prependId="false">
<p:tabView id="tabViewCadastroEcf">
<ui:include src="/restrito/cliente_software_house/tabClienteCadastro.xhtml" />
<ui:include src="/restrito/cliente_software_house/tabContatosCadastro.xhtml" />
<ui:include src="/restrito/cliente_software_house/tabEnderecosCadastro.xhtml" />
<ui:include src="/restrito/cliente_software_house/tabEcfCadastro.xhtml" />
</p:tabView>
</h:form>
</h:panelGroup>
</ui:define>
<ui:define name="dialogsAdicionais">
<ui:include src="/restrito/pessoa/dialogTabelaPessoas.xhtml" />
<ui:include src="/restrito/contador/dialogVinculoContador.xhtml" />
<ui:include src="/restrito/item_categoria_cliente/dialogVinculoItemCategoriaCliente.xhtml" />
<ui:include src="/restrito/grupo_cliente/dialogVinculoGrupoCliente.xhtml" />
<ui:include src="/restrito/ecf/dialogHistoricos.xhtml" />
<p:confirmDialog id="exclusaoHistoricoEcfId" appendTo="@(body)"
message="Voce deseja realmente excluir?" header="Confirmação"
severity="alert" widgetVar="exclusaoHistoricoEcf">
<h:form prependId="false">
<div style="margin-left: 60px">
<p:commandButton value="Sim" process="@this"
oncomplete="exclusaoHistoricoEcf.hide()" update="@([id$=formDialogHistoricosECF])"
actionListener="#{ecfController.removerHistorico}">
</p:commandButton>
<p:commandButton value="Não" process="@this"
onclick="exclusaoHistoricoEcf.hide()" />
</div>
</h:form>
</p:confirmDialog>
<p:confirmDialog id="exclusaoEcfId" appendTo="@(body)"
message="Voce deseja realmente excluir?" header="Confirmação"
severity="alert" widgetVar="exclusaoEcf">
<div style="margin-left: 60px">
<p:commandButton value="Sim" process="@this"
oncomplete="exclusaoEcf.hide()" update="@([id$=rendererTabEcf])"
actionListener="#{controller.removerEcf}">
</p:commandButton>
<p:commandButton value="Não" process="@this"
onclick="exclusaoEcf.hide()" />
</div>
</p:confirmDialog>
</ui:define>
正如您所看到的所有选项卡都被包含在内,所以这里是带有我要处理的字段的选项卡,按钮是id =“botaoSalvarCadastro”的按钮..
<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">
<p:tab title="Cadastro">
<ui:include src="/restrito/pessoa/compositeVinculoPessoa.xhtml" />
<hr width="100%"/>
<h:panelGroup id="dadosClienteSH" layout="block">
<p:panelGrid id="camposCadastroClienteSH" columns="4" style="max-width:1000px; width:100%">
<p:outputLabel value="Contador: "/>
<h:panelGroup id="pgContador" layout="block" style="display: inline-block; float: left; ">
<p:inputText disabled="true"
value="#{contadorController.entidade.pessoa.nome_razaoSocial}" style="margin-right:20px; min-width:186px"/>
<p:commandButton value="..." actionListener="#{contadorController.irPesquisa}" process="@this"
oncomplete="PF('dialogVinculoContador').show()" update=":formDialogVinculoContador"/>
</h:panelGroup>
<p:outputLabel value="Item de Categoria de Cliente: "/>
<h:panelGroup id="pgItemCategoriaCliente" layout="block" style="display: inline-block; float: left; ">
<p:inputText disabled="true"
value="#{itemCategoriaClienteController.entidade.descricao}" style="margin-right:20px; min-width:186px"/>
<p:commandButton value="..." actionListener="#{itemCategoriaClienteController.irPesquisa}" process="@this"
oncomplete="PF('dialogVinculoItemCategoriaCliente').show()" update=":formDialogVinculoItemCategoriaCliente"/>
</h:panelGroup>
<p:outputLabel value="Grupo de Cliente: "/>
<h:panelGroup id="pgItemCategoriaGrupoCliente" layout="block" style="display: inline-block; float: left; ">
<p:inputText disabled="true"
value="#{grupoClienteController.entidade.descricao}" style="margin-right:20px; min-width:186px"/>
<p:commandButton value="..." actionListener="#{grupoClienteController.irPesquisa}" process="@this"
oncomplete="PF('dialogVinculoGrupoCliente').show()" update=":formDialogVinculoGrupoCliente"/>
</h:panelGroup>
<p:outputLabel value="MacAdress Servidor: "/>
<p:inputText id="macAdress" value="#{controller.entidade.macAdressServidor}" disabled="#{controller.status == 'VISUALIZACAO'}"/>
<p:outputLabel value="Data de Travamento: "/>
<p:calendar id="licensaLimiteTravaCadastro" pattern="dd/MM/yyyy" mask="true" disabled="#{controller.status == 'VISUALIZACAO'}"
required="true" requiredMessage="Campo Obrigatório" value="#{controller.entidade.licensaLimiteTrava}"/>
<p:outputLabel value="Data Limite para Update: "/>
<p:calendar id="licensaLimiteUpdateCadastro" pattern="dd/MM/yyyy" mask="true" disabled="#{controller.status == 'VISUALIZACAO'}"
required="true" requiredMessage="Campo Obrigatório" value="#{controller.entidade.licensaLimiteUpdate}"/>
<p:outputLabel value="Data Limite da Garantia: "/>
<p:calendar id="licensaLimiteGarantiaCadastro" pattern="dd/MM/yyyy" mask="true" disabled="#{controller.status == 'VISUALIZACAO'}"
required="true" requiredMessage="Campo Obrigatório" value="#{controller.entidade.licensaLimiteGarantia}"/>
<p:outputLabel value="Data Limite do Contrato: "/>
<p:calendar id="licensaLimiteContratoCadastro" pattern="dd/MM/yyyy" mask="true" disabled="#{controller.status == 'VISUALIZACAO'}"
required="true" requiredMessage="Campo Obrigatório" value="#{controller.entidade.licensaLimiteContrato}"/>
<p:outputLabel value="Data Limite do Atraso: "/>
<p:calendar id="licensaLimiteAtrasoCadastro" pattern="dd/MM/yyyy" mask="true" disabled="#{controller.status == 'VISUALIZACAO'}"
required="true" requiredMessage="Campo Obrigatório" value="#{controller.entidade.licensaLimiteAtraso}"/>
</p:panelGrid>
</h:panelGroup>
<p:commandButton id="botaoSalvarCadastro" actionListener="#{controller.salvar}" style="margin-top:15px"
value="Salvar" process="dadosClienteSH"/>
</p:tab>
我已经尝试过使用@([id $ = dadosClienteSH]),我也尝试逐字段处理,无论如何它只用process =“@ this”到达我的bean。
我坚持这个,希望有人能给我一些启示。
答案 0 :(得分:0)
我在阅读了许多Primefaces论坛帖子后想出来了,问题出现了,因为我正在尝试处理一个不包含我的按钮的panelGroup,因此按钮根本没有处理。为了解决这个问题,我在按钮的process属性中添加了button和panelGroup。有代码:
<p:commandButton id="botaoSalvarCadastro" actionListener="#{controller.salvar}" style="margin-top:15px"
value="Salvar" update="@form" process="@this,dadosCadastro" ajax="true" rendered="#{controller.status != 'VISUALIZACAO'}"/>