gpt4 book ai didi

ajax - 如何在 ajax update/process/render/execute 中引用#{cc.clientId}?

转载 作者:行者123 更新时间:2023-12-04 13:11:34 25 4
gpt4 key购买 nike

我不知道如何在 update 中引用复合组件的后代组件或 process (别名 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。

最佳答案

您需要使用 NamingContainer 作为绝对客户端 ID 的前缀分隔符默认为 : .

update=":#{cc.clientId}"

也可以看看:
  • How to find out client ID of component for ajax update/render? Cannot find component with expression "foo" referenced from "bar"
  • 关于ajax - 如何在 ajax update/process/render/execute 中引用#{cc.clientId}?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8412914/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com