我如何从表单外部更新表单中的字段

时间:2019-01-18 21:21:33

标签: jsf primefaces facelets

我需要更新panelGrid内位于h:form内的一些输入字段,但必须将触发器抛出此窗体之外。
panelGrid甚至相同,但是形式是动态的。我不能使用固定标识。

有人可以帮我吗?

这是动态表格的示例

<ui:composition xmlns="http://www.w3.org/1999/xhtml" xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:h="http://java.sun.com/jsf/html"
    xmlns:componente="http://java.sun.com/jsf/composite/componente" xmlns:f="http://java.sun.com/jsf/core" xmlns:p="http://primefaces.org/ui"
    template="/WEB-INF/template/principal.xhtml">
    <div id="global">
        <ui:define name="content">
            <h:form id="formDinamic">
                <ui:include src="/pages/templates/adicionaisUsuario.xhtml" />

                <p:remoteCommand name="updateCep" process="@form:fixedPanel" />
            </h:form>

            <ui:include src="/pages/dialogSearchCepPorEndereco.xhtml">
                <ui:param name="modo" value="E" />
            </ui:include>
        </ui:define>
    </div>
</ui:composition>

页面adicionaisUsuario.xhtml

<p:panelGrid id="fixedPanel" column="4">

    <p:inputText id="input1" value="#{crudMb.object1.value1}" />
    <p:inputText id="input2" value="#{crudMb.object1.value2}" />
    <p:inputText id="input3" value="#{crudMb.object1.value3}" />

    <p:commandButton actionListener="#{enderecoMb.doPrepare}" oncomplete="PF('dlgPesqCep').show();"
        process="@this :dialogPesquisaCep" update="fixedPanel">
        <f:setPropertyActionListener target="#{enderecoMb.object1}" value="#{crudMb.object1}" />
        <f:setPropertyActionListener target="#{enderecoMb.tipoEndereco}" value="Residencial" />
    </p:commandButton>

</p:panelGrid>

我的对话框

<?xml version="1.0" encoding="UTF-8"?>
<ui:composition 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">

    <p:dialog id="dialogPesquisaCep" position="center" modal="true" widgetVar="dlgPesqCep" resizable="false" width="670"
        height="500" header="#{enderecoMb.titulo}" onShow="rc();">

        <h:form id="formPesquisaCep">
            <p:remoteCommand name="rc" resetValues="true" update="dtlistCeps pBuscaCep" />
                <p:messages closable="true" id="msgCep" redisplay="false" />

                <p:panelGrid id="pBuscaCep" >
                    <p:row>
                        inputs for search...
                    </p:row>
                    <p:row>
                        <p:column>
                            <p:commandButton value="" id="btnPesquisaCep" actionListener="#{enderecoMb.doEventListEnderecos()}"
                                styleClass="btn_pesquisar" style="margin-left: 9px;" update="msgCep dtlistCeps">
                                <f:setPropertyActionListener value="#{modo}" target="#{enderecoMb.modo}" />
                            </p:commandButton>
                        </p:column>
                    </p:row>
                </p:panelGrid>
            </fieldset>

            <p:dataTable id="dtlistCeps" var="end" value="#{enderecoMb.enderecos}" emptyMessage="#{m['nenhum.registro']}"
              rowIndexVar="index"
              rowKey="#{end.cep}" selectionMode="single">

                <p:ajax event="rowSelect" listener="#{enderecoMb.onRowSelectEndereco}" oncomplete="PF('dlgPesqCep').hide();"
                    update="@(:table[name*='fixedPanel'])">
                    <f:setPropertyActionListener target="#{enderecoMb.enderecoPesquisado}" value="#{end}" />
                </p:ajax>

                <p:columns... />

            </p:dataTable>

        </h:form>

    </p:dialog>
</ui:composition>

我显示的对话框是单击 adicionaisUsuario.xhtml 页内的p:commandButton的对话框,搜索并选择行之一(通过onRowSelectEndereco方法),隐藏 dialogPesquisaCep 并需要更新p:panelGrid fixedPanel

中的输入字段

谢谢您的帮助

0 个答案:

没有答案