小编典典

如何在Ajax更新/处理/渲染/执行中引用#{cc.clientId}?

ajax

我不知道如何在updateprocess(别名renderexecute)中引用复合组件的后代组件。

我有这个复合组件resources/components/crud.xhtml

<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:p="http://primefaces.org/ui"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:c="http://java.sun.com/jsf/composite">

    <c:interface>
        <c:attribute name="controller" required="true" />
        <c:facet name="fields" required="true"/>
    </c:interface>

    <c:implementation>

        <p:dataTable 
            id="table"
            value="#{cc.attrs.controller.autoResultModel}" 
            var="unit" 
            paginator="true" 
            rows="10" 
            lazy="true"  
            paginatorAlwaysVisible="true"
            paginatorPosition="top"
            paginatorTemplate="{CurrentPageReport} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
            currentPageReportTemplate="{totalRecords} records found, Page: {currentPage}/{totalPages}"
            rowsPerPageTemplate="5,10,15" 
            sortBy="#{unit.creationTime}"
            sortOrder="descending"
            selectionMode="single"
            selection="#{cc.attrs.controller.selected}">

            <p:ajax event="rowSelect" update="editDialog trashDialog table:commands"/>

            <f:facet name="header">
                <h:panelGroup id="commands" layout="block">
                    <p:commandButton id="newButton" value="new" image="ui-icon ui-icon-plusthick" oncomplete="editDialog.show()" actionListener="#{cc.attrs.controller.clearSelected()}" process="@this" update="#{cc.clientId}" />
                    <p:commandButton value="edit" image="ui-icon ui-icon-wrench" onclick="editDialog.show()" type="button" disabled="#{cc.attrs.controller.selected.id == null}"/>
                    <p:commandButton value="delete" image="ui-icon ui-icon-trash" onclick="trashDialog.show()" type="button" disabled="#{cc.attrs.controller.selected.id == null}"/>
                </h:panelGroup>
            </f:facet>

            <c:insertChildren/>

        </p:dataTable>

        <h:panelGroup id="editDialog">
            <p:dialog modal="true" widgetVar="editDialog" showEffect="fold" hideEffect="puff">

                <f:facet name="header">
                    <h:outputText value="#{bundle['create']}" rendered="#{cc.attrs.controller.selected.id == null}"/>
                    <h:outputText value="#{bundle['update']}" rendered="#{cc.attrs.controller.selected.id != null}"/>
                </f:facet>

                <h:panelGroup layout="block">

                    <c:renderFacet name="fields"/>

                    <br/>

                    <p:commandButton value="#{bundle['create']}" actionListener="#{cc.attrs.controller.create}" process="editDialog" update="table" oncomplete="closeDialog(xhr, status, args, editDialog)" rendered="#{cc.attrs.controller.selected.id == null}"/>
                    <p:commandButton value="#{bundle['update']}" actionListener="#{cc.attrs.controller.update}" process="editDialog" update="table" oncomplete="closeDialog(xhr, status, args, editDialog)" rendered="#{cc.attrs.controller.selected.id != null}"/>
                    <p:commandButton value="#{bundle['copy']}" actionListener="#{cc.attrs.controller.create}" process="editDialog" update="table" oncomplete="closeDialog(xhr, status, args, editDialog)" rendered="#{cc.attrs.controller.selected.id != null}">
                        <f:setPropertyActionListener target="#{cc.attrs.controller.selected.id}" value="#{null}"/>
                    </p:commandButton>
                </h:panelGroup>

            </p:dialog>

        </h:panelGroup>

        <p:dialog modal="true" header="asdasd" widgetVar="trashDialog" hideEffect="explode" showEffect="explode"> 
            <h:panelGroup id="trashDialog" layout="block">
                <h:outputText value="#{bundle['trashconfirm']}">
                    <f:param name="name" value="#{cc.attrs.controller.selected.name}"/>
                </h:outputText>
            </h:panelGroup>

            <p:commandButton value="#{bundle['confirm']}" actionListener="#{cc.attrs.controller.destroy}" process="@this" update="table" oncomplete="closeDialog(xhr, status, args, trashDialog)"/>
        </p:dialog>
    </c:implementation>
</html>

通过此页面调用test.xhtml

<html xmlns="http://www.w3.org/1999/xhtml"
        xmlns:ui="http://java.sun.com/jsf/facelets"
        xmlns:h="http://java.sun.com/jsf/html"
        xmlns:p="http://primefaces.org/ui"
        xmlns:f="http://java.sun.com/jsf/core"
        xmlns:cc="http://java.sun.com/jsf/composite/components">


    <h:head>
        <title>Default Title</title>
        <h:outputStylesheet name="css/screen.css"/>
        <h:outputScript name="js/common.js"/>
    </h:head>

    <h:body>

        <p:growl id="messages" autoUpdate="true"/>

        <h:form id="itemForm">

            <cc:crud id="itemCrud" controller="#{itemController}">

                <f:facet name="fields">
                    <h:panelGrid columns="3">
                        <h:outputLabel value="manufacturer" for="manufacturer"/>
                        <p:selectOneMenu id="manufacturer" value="#{itemController.selected.manufacturer}" converter="#{manufacturerController.converter}">
                            <f:selectItems value="#{manufacturerController.facade.findAll()}" var="e" itemLabel="#{e.title}" itemValue="#{e}"/>
                        </p:selectOneMenu>
                        <p:message for="manufacturer"/>

                        <h:outputLabel value="partNumber" for="partNumber"/>
                        <p:inputText id="partNumber" value="#{itemController.selected.partNumber}"/>
                        <p:message for="partNumber"/>

                        <h:outputLabel value="configurationIndex" for="configurationIndex"/>
                        <p:inputText id="configurationIndex" value="#{itemController.selected.configurationIndex}"/>
                        <p:message for="configurationIndex"/>
                    </h:panelGrid>
                </f:facet>

                <p:column headerText="#{bundle['manufacturer']}" filterBy="#{unit.manufacturer.title}" sortBy="#{unit.manufacturer.title}">
                    #{unit.manufacturer.title}
                </p:column>

                <p:column headerText="#{bundle['partNumber']}" filterBy="#{unit.partNumber}" sortBy="#{unit.partNumber}">
                    #{unit.partNumber}
                </p:column>

                <p:column headerText="#{bundle['configurationIndex']}" filterBy="#{unit.configurationIndex}" sortBy="#{unit.configurationIndex}">
                    #{unit.configurationIndex}
                </p:column>

                <p:column headerText="#{bundle['modifyStatus']}" filterBy="#{unit.modifyStatus}" sortBy="#{unit.modifyStatus}">
                    #{unit.modifyStatus}
                </p:column>

                <p:column headerText="#{bundle['description']}" filterBy="#{unit.description}" sortBy="#{unit.description}">
                    #{unit.description}
                </p:column>

            </cc:crud>

        </h:form>
    </h:body>
</html>

我有这个输出:

AVVERTENZA: PWC4011: Unable to set request character encoding to UTF-8 from context /epcsdb, because request parameters have already been read, or ServletRequest.getReader() has already been called
INFO: Skipping call to libraryExists().  Please set context-param com.sun.faces.enableMissingResourceLibraryDetection to true to verify if library http://java.sun.com/jsf/composite/components actually exists
INFO: Cannot find component with identifier "itemForm:itemCrud:table:newButton" in view.
INFO: Cannot find component with identifier "itemForm:itemCrud" in view.
INFO: Cannot find component with identifier "editDialog" in view.
INFO: Cannot find component with identifier "trashDialog" in view.
INFO: Cannot find component with identifier "itemForm:itemCrud:j_idt34" in view.

结果是没有任何ajax调用更新任何组件。我不明白为什么找不到“
itemForm:itemCrud:table:newButton”。仅用引用process="@this"

我正在使用primefaces 3.0.RC1-SNAPSHOT和Mojarra 2.1.3_01。


阅读 204

收藏
2020-07-26

共1个答案

小编典典

您需要在绝对客户端ID前面加上NamingContainer默认的分隔符:

update=":#{cc.clientId}"
2020-07-26