首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用Ajax结果更新组件出现异常

使用Ajax结果更新组件出现异常
EN

Stack Overflow用户
提问于 2012-10-25 18:56:32
回答 1查看 415关注 0票数 0

似乎我根本无法掌握使用Ajax更新组件是如何工作的。我一直收到异常“无法找到带有标识符的组件":menu-item-container”引用自“j_idt12:0:j_idt16:j_idt76”。“

这是我的代码:

代码语言:javascript
复制
<!DOCTYPE html>
    <html 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">

    <f:view contentType="text/html">
    <h:head>
        <title><ui:insert name="pageTitle"></ui:insert></title>
    </h:head>

    <h:body>
        <h:outputStylesheet library="css" name="style.css" />
        <div class="menu-navigation">
            <ul>
                <li>Menu</li>
                <ui:repeat var="category"
                    value="#{restaurantsBean.restaurant.categories}">
                    <h:form>
                        <li><p:commandLink update=":menu-item-container">
                                <div>
                                    #{category.name}
                                    <f:setPropertyActionListener              value="#{category.id}"
                                        target="#                   {restaurantMenuBean.selected}" />
                                </div>
                            </p:commandLink></li>
                    </h:form>
                </ui:repeat>
            </ul>
        </div>

        <div id="menu-item-container">

            <ui:repeat var="category"
                value="#{restaurantsBean.restaurant.categories}">
                <p:outputPanel>
                    <h:panelGroup id="pangroup" layout="block"
                        rendered="#{restaurantMenuBean.active(category.id)}">
                        <div class="some-heading">
                            <h2>#{category.name}</h2>
                        </div>
                        <div class="category-description">#{category.description}</div>

                        <ui:repeat var="item" value="#{category.items}">
                            <p:outputPanel
                                rendered="#{restaurantMenuBean.needLightbox(item)}">
                                <ui:include src="/lightbox-item.xhtml"></ui:include>
                            </p:outputPanel>
                            <p:outputPanel
                                rendered="#{!restaurantMenuBean.needLightbox(item)}">
                                <ui:include src="/nolightbox-item.xhtml"></ui:include>
                            </p:outputPanel>
                        </ui:repeat>

                    </h:panelGroup>
                </p:outputPanel>
            </ui:repeat>

        </div>
    </h:body>
    </f:view>
    </html>

这是html源输出的相关区域,它告诉我,我的"menu-item-container“就在根目录,而update-attribute只需要在其id前面有一个分隔标记":”。

代码语言:javascript
复制
<div id="menu-item-container"><span id="j_idt17:0:j_idt64"></span><span id="j_idt17:1:j_idt64"><div id="j_idt17:1:pangroup">
                        <div class="some-heading">
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-10-25 19:35:50

将使用UIViewRoot#findComponent()中描述的算法解析要更新的组件。很明显,它只能找到完全有价值的JSF组件。

但是,您的menu-item-container是一个普通的HTML元素,因此在<div>组件树中不可用。

将其替换为一个完整的JSF组件。

代码语言:javascript
复制
<h:panelGroup id="menu-item-container" layout="block">

默认情况下,<h:panelGroup>呈现<span>layout="block"将其转换为<div>

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/13067070

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档