Primefaces:对话框隐藏时不会更新文本字段

问题描述:

我正在尝试更新对话框中的文本字段.文本字段位于父组件中.但它没有发生.如果我在命令按钮的更新中给出文本字段的 ID.我遇到了错误:javax.faces.FacesException:找不到从tabView:lkpSltRec"引用的标识符为customerCode"的组件

Im trying to update text field from dialog box .The text field is in the parent component. But its not happening . If i give the id of text field in the update of command button . I encountered the error : javax.faces.FacesException: Cannot find component with identifier "customerCode" referenced from "tabView:lkpSltRec"

因为它无法找到组件 id .我已经使用了替代方案.我采用了隐藏字段.单击命令按钮后,隐藏字段得到更新,并通过简单的 javascript 函数即时更新父组件的文本字段.从对话框中命令按钮的 oncomplete 调用 javascript 函数.因为,根据项目要求,我必须通过 primefaces 实现它,而不是通过 javascript.请建议我在 primefaces 中的方法.下面是代码片段:

Since it is not able to find the component id . I have used the alternative . I have taken the hidden field .After command button is clicked , the hidden field gets updated and through simple javascript function im updating the text field of parent component .The javascript function is called from oncomplete of command button in the dialog box. Since ,as per project requirement i have to achieve it through primefaces only not through javascript . Plz, suggest me the approach in primefaces . Below is the code snippet:

这里的 ecap:lookup 是自定义组件.

Here ecap:lookup is the the customize component.

    Selected Customer <p:inputText id="customerCode"
        value="#{sixthTabBBean.customerName}" label="Selected Adddress"></p:inputText>
    Selected Customer City <p:inputText id="selectedCity"   value="#{sixthTabBBean.customerCity}"  ></p:inputText>
    <ecap:lookup lookupId="LOV0072" inputId="customerCode" clickStatus="city"
        defaultDDValueIndex="0" title="CustomerCode"></ecap:lookup>

        New LOV <ecap:lookup lookupId="LOV0092" inputId="customerCode" clickStatus="none"
        defaultDDValueIndex="0" title="CustomerCode"></ecap:lookup>

    City<p:inputText id="custCity" value="#{sixthTabBBean.customerCity}"
        disabled="true" label="City"></p:inputText>
    Selected Customer <p:inputText id="customerCode1"
        value="#{sixthTabBBean.customerName}" label="Selected Adddress" ></p:inputText>
    Selected Customer City <p:inputText id="selectedCity1"  value="#{sixthTabBBean.customerCity}"  ></p:inputText>
    Selected Customer State <p:inputText id="selectedSate1"     value="#{sixthTabBBean.customerState}"  ></p:inputText>
    <ecap:lookup lookupId="LOV0098" inputId="customerCode" clickStatus="state"
        defaultDDValueIndex="0" title="CustomerCode"></ecap:lookup>
    <p:dialog id="lkpDialog" widgetVar="lpDialogVar" header="Lookup"
        modal="true" width="1000" height="600"
        rendered="#{lookupSearch.popupRender}"  >
        <h:form  rendered="#{lookupSearch.popupRender}"  prependId="false">
            <h:panelGrid cellpadding="10" id="diaFrmId">
                <p:dataTable id="newfdt" var="flxSearch"
                    value="#{lookupSearch.lkpSearchCriteriaList}">

                    <p:column id="newwhc">
                        <f:facet name="header">
                            <h:outputLabel value="Search Fields"></h:outputLabel>
                        </f:facet>
                        <p:selectOneMenu styleClass="fdd180" id="newwdd"
                            value="#{flxSearch.searchCriterion.whereClause}">
                            <f:selectItems value="#{flxSearch.whrClausDropdown}" />
                        </p:selectOneMenu>
                    </p:column>

                    <p:column id="newcoc">
                        <f:facet name="header">
                            <h:outputLabel value="Conditions"></h:outputLabel>

                        </f:facet>
                        <p:selectOneMenu id="newco" styleClass="fdd95"
                            value="#{flxSearch.searchCriterion.operator}">
                            <f:selectItems id="newcriOperatorItms"
                                value="#{flxSearch.operatorDropdown}" />
                        </p:selectOneMenu>
                    </p:column>

                    <p:column id="newcic">
                        <f:facet name="header">
                            <h:outputLabel value="Value"></h:outputLabel>

                        </f:facet>
                        <p:inputText id="newcriInpNm"
                            rendered="#{!flxSearch.inputDate and !flxSearch.boolValue and !flxSearch.required}"
                            styleClass="285 ftb" deferChangeEvent="true"
                            value="#{flxSearch.searchCriterion.value}"
                            maxlength="#{flxSearch.maxLength}"
                            disabled="#{flxSearch.disableInput}" partialSubmit="true"
                            labelValue="#{flxSearch.searchCriterion.label}"
                            required="#{flxSearch.required}">
                        </p:inputText>

                        <p:inputText id="newcriInpM"
                            rendered="#{!flxSearch.inputDate and !flxSearch.boolValue and flxSearch.required }"
                            value="#{flxSearch.searchCriterion.value}"
                            maxlength="#{flxSearch.maxLength}"
                            disabled="#{flxSearch.disableInput}"
                            labelValue="#{flxSearch.searchCriterion.label}"
                            required="#{flxSearch.required}">

                        </p:inputText>

                        <p:selectOneMenu styleClass="fdd" id="newbldd"
                            value="#{flxSearch.searchCriterion.value}"
                            disabled="#{flxSearch.disableInput}"
                            rendered="#{flxSearch.boolValue }">
                            <f:selectItems value="#{flxSearch.booleanDropdown}" />
                        </p:selectOneMenu>

                        <p:calendar id="newcriDtNm" size="9"
                            rendered="#{flxSearch.inputDate and !flxSearch.boolValue and !flxSearch.required }"
                            disabled="#{flxSearch.disableInput}" showOn="button"
                            value="#{flxSearch.searchCriterion.value}"
                            labelValue="#{flxSearch.searchCriterion.label}">
                        </p:calendar>

                        <p:calendar id="newcriDtM" size="9"
                            rendered="#{flxSearch.inputDate and !flxSearch.boolValue and flxSearch.required }"
                            disabled="#{flxSearch.disableInput}"
                            value="#{flxSearch.searchCriterion.value}"
                            enableChangeDetector="false" partialSubmit="true"
                            labelValue="#{flxSearch.searchCriterion.label}"
                            required="#{flxSearch.required}" showOn="button">
                        </p:calendar>

                    </p:column>
                </p:dataTable>
                <!-- hidden text used to update values in the parent component -->
                <p:inputText  type="hidden" id="hiddencustomerCode"  
                    value="#{sixthTabBBean.customerName}"   ></p:inputText>
                <p:inputText  type="hidden" id="hiddencustCity"  
                    value="#{sixthTabBBean.customerCity}"   ></p:inputText>
                <p:inputText  type="hidden" id="hiddencustState"  
                value="#{sixthTabBBean.customerState}"   ></p:inputText>

                <p:fieldset legend="Combined By">
                    <h:panelGrid columns="2" cellpadding="10">
                        <p:selectOneRadio id="newSlctDrk"
                            valueChangeListener="#{lookupSearch.getSelectedLogOpr}"
                            value="#{lookupSearch.selLogOpr}"
                            title="Combine all search criteria with AND or OR">
                            <f:selectItems id="newSlctDrkItms"
                                value="#{lookupSearch.logicalOperators}" />
                        </p:selectOneRadio>
                    </h:panelGrid>
                </p:fieldset>
                <h:panelGrid columns="3">
                    <p:commandButton value="Find" id="lkpfndDg" update="resultFldSet"
                        actionListener="#{lookupSearch.search}">
                    </p:commandButton>
                    <p:commandButton value="Clear" id="lkpClearDg"
                        actionListener="#{lookupSearch.clear}" />
                </h:panelGrid>
                <p:fieldset legend="Result" id="resultFldSet">
                        <p:dataTable binding="#{lookupSearch.lkpResultDataTable}"
                            value="#{lookupSearch.searchResultsForPage}"></p:dataTable>
                </p:fieldset>
                <p:commandButton value="Select" id="lkpSltRec" update="customerCode"
                    oncomplete="lpDialogVar.hide();insertSelectedValue();"
                    actionListener="#{lookupSearch.selectValue}" />
            </h:panelGrid>
        </h:form>
    </p:dialog>

</h:panelGrid>

这里的 ecap:lookup 是自定义组件.

Here ecap:lookup is the customize component.

终于,我得到了解决方案.我遇到的例外是因为表单标签.从对话框中触发的 ajax 事件无法在表单之外找到组件.在这种情况下使用::#{p:component('componentId')}

Finally, i have got the solution . The exception i have encountered is because of the form tag . The ajax event fired from the dialog is not able to find the component outside the form .In this case use: :#{p:component('componentId')}

在这里,它不仅会在表单内搜索 id,还会在表单外搜索.

Here it will search the id not only within the form but outside of it.