本文介绍了添加第二个复合组件后,Error& lt; f:ajax>包含未知的ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试在我的应用程序中使用复合组件.当我添加了第一个组件时,它已经起作用了,但是当我再次添加了组件时,却出现了错误:

I try to use composite components in my application. When i have added first component it has worked, but when i have added component once again, i have gotten error:

这是实现代码:

<cc:interface>
    <!-- properties -->
    <cc:attribute name="isDisabled" type="java.lang.Boolean" />
    <cc:attribute name="freeForm" type="java.lang.String" />
    <cc:attribute name="houseNum" type="java.lang.String" />
    <cc:attribute name="korpusNum" type="java.lang.String" />
    <cc:attribute name="flatNum" type="java.lang.String" />

    <cc:attribute name="kladrRegion" type="java.lang.String" />
    <cc:attribute name="cbKladrRegion" type="javax.faces.component.html.HtmlSelectOneMenu" />
    <cc:attribute name="kladrRegions" type="java.util.List" />

    <cc:attribute name="kladrCity" type="java.lang.String" />
    <cc:attribute name="cbKladrCity" type="javax.faces.component.html.HtmlSelectOneMenu" />
    <cc:attribute name="kladrCities" type="java.util.List" />

    <cc:attribute name="kladrSearch" type="java.lang.String" />
    <cc:attribute name="cbKladrSearch" type="org.icefaces.ace.component.combobox.ComboBox" />
    <cc:attribute name="kladrSearches" type="java.util.List" />

    <!-- methods -->
    <cc:attribute name="listener"
                  method-signature="void actionListener(javax.faces.event.AjaxBehaviorEvent)"/>
    <cc:attribute name="kladrRegionChange"
                  method-signature="void actionListener(javax.faces.event.AjaxBehaviorEvent)"/>
    <cc:attribute name="kladrCityChange"
                  method-signature="void actionListener(javax.faces.event.AjaxBehaviorEvent)"/>
    <cc:attribute name="kladrDlgCloseClick"
                  method-signature="void actionListener(javax.faces.event.AjaxBehaviorEvent)"/>
    <cc:attribute name="kladrDlgSaveClick"
                  method-signature="void actionListener(javax.faces.event.AjaxBehaviorEvent)"/>
    <cc:attribute name="searchKladrAction"
                  method-signature="java.lang.String action(java.lang.String)"/>
</cc:interface>

<cc:implementation>
    <h:panelGrid styleClass="panelGrid" columns="2">
        <h:panelGroup styleClass="panelGroup">
            <div class="searchWrap">
                <h:commandLink id="searchButton"
                               disabled="#{cc.attrs.isDisabled}"
                               onclick="openKladrDialog(this, '#{cc.clientId}')">
                    <h:graphicImage value="/resources/images/search.png"
                                    alt="#{usertag.labelSearchAddr}" />
                    <f:ajax event="click"
                            render="kladrRegion-dctKladrRegion"
                            listener="#{cc.attrs.listener}"/>
                </h:commandLink>
            </div>
        </h:panelGroup>

        ...etc.

    </h:panelGrid>

    <!-- dialog -->
    <div id="#{cc.clientId}_kladrDialog">
        <h:panelGrid styleClass="panelGrid" columns="3">
            <h:outputLabel value="Country" class="outputLabel" for="kladrCountry" />
            <h:panelGroup styleClass="panelGroup">
                <ice:inputText disabled="true" value="Russia"
                               styleClass="ui-inputfield ui-corner-all inputText kladrSearchFormInput kladrSearchFormInputWidth" />
                <h:inputHidden id="kladrCountry" value="179" />
            </h:panelGroup>
            <h:outputLabel />

            <h:outputLabel value="Region" class="outputLabel" />
            <h:selectOneMenu id="kladrRegion-dctKladrRegion"
                             value="#{cc.attrs.kladrRegion}" >
                <f:selectItems value="#{cc.attrs.kladrRegions}" var="region"
                               itemLabel="#{region.value}" itemValue="#{region.id}" />
                <f:ajax render="@this kladrCity-dctKladrCity"
                        listener="#{cc.attrs.kladrRegionChange}" />
            </h:selectOneMenu>

            ... etc.
    </div>

</cc:implementation>

这是标签的代码:

<kladr:usertag  isDisabled="#{PolicyBean.policyDisabled}"
                freeForm="#{PolicyBean.policyAuto.holder.baseAddress.freeForm}"
                houseNum="#{PolicyBean.policyAuto.holder.baseAddress.houseNum}"
                korpusNum="#{PolicyBean.policyAuto.holder.baseAddress.korpusNum}"
                flatNum="#{PolicyBean.policyAuto.holder.baseAddress.flatNum}"

                kladrRegion="#{PolicyBean.kladrRegion}"
                cbKladrRegion="#{PolicyBean.cbKladrRegion}"
                kladrRegions="#{PolicyBean.kladrRegions}"

                kladrCity="#{PolicyBean.kladrCity}"
                cbKladrCity="#{PolicyBean.cbKladrCity}"
                kladrCities="#{PolicyBean.kladrCities}"

                kladrSearch="#{PolicyBean.kladrSearch}"
                cbKladrSearch="#{PolicyBean.cbKladrSearch}"
                kladrSearches="#{PolicyBean.kladrSearches}"

                listener="#{PolicyBean.holderKladrDlgOpenClick}"
                kladrRegionChange="#{PolicyBean.kladrRegionChange}"
                kladrCityChange="#{PolicyBean.kladrCityChange}"
                kladrDlgCloseClick="#{PolicyBean.kladrDlgCloseClick}"
                kladrDlgSaveClick="#{PolicyBean.kladrDlgSaveClick}"
                searchKladrAction="#{PolicyBean.kladrSearchClick(PolicyBean.kladrSearch)}" />

有什么想法吗?

推荐答案

问题是,您的< h:selectOneMenu id ="kladrRegion-dctKladrRegion"> 位于另一个父组件中,而不是您的< h:commandLink id ="searchButton" ... .

The problem is, that your <h:selectOneMenu id="kladrRegion-dctKladrRegion"> is in another parent component than your <h:commandLink id="searchButton" ....

如果您指定正确的绝对组件ID(或将对话框移至同一父对象中),它将正常工作.

It will work correctly, if you specify the correct absolute component id (or move your dialog inside the same parent).

有关如何找到正确的方法,请参见在JSF中按ID查找组件组件ID.

See Find component by ID in JSF on how to find the correct component id.

该异常告诉您,组件< h:panelGroup> 中没有ID为"kladrRegion-dctKladrRegion" 的组件,而id为"j_idt202" .

The exception tells you that there is not component with id "kladrRegion-dctKladrRegion" inside the component <h:panelGroup> whid got the generated id "j_idt202".

如果您使用的是PrimeFaces,则可以使用EL函数 component('id')返回正确的组件ID.参见 http://www.primefaces.org/docs/guide/primefaces_user_guide_5_1.pdf,第11.2章.

If you're using PrimeFaces, you can use the EL Function component('id') which returns the correct component id. See http://www.primefaces.org/docs/guide/primefaces_user_guide_5_1.pdf, chapter 11.2.

这篇关于添加第二个复合组件后,Error&amp; lt; f:ajax&gt;包含未知的ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-31 00:53