0

似乎我根本无法理解使用 Ajax 更新组件的工作原理。我不断收到异常“找不到标识符为“:menu-item-container”的组件,引用自“j_idt12:0:j_idt16:j_idt76”。

这是我的代码:

<!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”就在根目录下,而更新属性只需要在其 id 前面有一个分隔标记“:”。

<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">
4

1 回答 1

2

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

然而,您menu-item-container是一个纯 HTML<div>元素,因此在 JSF 组件树中不可用。

将其替换为完全值得的 JSF 组件。

<h:panelGroup id="menu-item-container" layout="block">

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

于 2012-10-25T11:35:50.403 回答