我有一个 JSP 2.0 <ui:component>
,里面有一个 <p:dataTable>
有一列使用 Composite 来呈现有关某些内容的特殊边框。现在我需要识别 <p:dataTabe>
在位于内容中的 ajax 呈现属性中。
<ui:component>
<p:dataTable id="dataTable" var="userItem" ... />
<p:column>
<my:borderBox id="borderBox">
<p:commandButton
action="#{userController.doDelete(userItem.id)}"
value="delete"
update="?????"/> <!-- How to address the dateTable? -->
</my:borderBox>
</p:column>
</p:dataTable>
<ui:component>
我的边框:
<html xmlns:composite="http://java.sun.com/jsf/composite" ...>
<composite:interface>
<composite:attribute name="styleClass" default="" type="java.lang.String"/>
</composite:interface>
<composite:implementation>
<h:panelGroup ...>
...
<composite:insertChildren/>
</h:panelGroup>
</composite:implementation>
我的想法是使用类似的东西
update=":#{component.namingContainer.parent.namingContainer.clientId}:dateTable
但是
component.namingContainer.parent
接缝为空。当我更换
<p:commandButton>
与此声明:Parent ClientId 1: #{component}
Parent ClientId 2: #{component.namingContainer}
Parent ClientId 3: #{component.namingContainer.clientId}
Parent ClientId 4: #{component.namingContainer.parent}
Parent ClientId 5: #{component.namingContainer.parent.namingContainer}
我得到这个输出:
Parent ClientId 1: javax.faces.component.html.HtmlPanelGroup@3d957419
Parent ClientId 2: javax.faces.component.UINamingContainer@23db9e8f
Parent ClientId 3: main_form:profilTabView:dataTable:0:borderBox
Parent ClientId 4:
Parent ClientId 5:
我不知道有什么问题呢:我的想法是确定列表是完全错误的还是有一些错误或有更好的方法? (但我不能为 dateTable 使用修复绝对标识符!)
版本:Primeface 3.2、Mojarra 2.1.6 on Glassfish 3.1.2
最佳答案
我有一个解决这个问题的方法。如果找不到其他解决方案,可以将其用作替代方案。解决方案是 jsf 和 javascript 之间的混合。为您的表定义一个小部件(例如“myTable”)。
<p:dataTable id="dataTable" var="userItem" ... widgetVar="myTable"/>
它创建了一个名为“myTable”的全局 javascript 变量。这个小部件对象包含一个 id。对于您的命令按钮(h:commandButton 不是 p:commandButton),您定义 onklick 事件:
<h:commandButton id="deleteItem" action="#{userController.doDelete(userItem.id)}"
value="delete" onclick="PrimeFaces.ab({formId:$(this).closest('form').attr('id'),source:this.id,process:'@all',update:myTable.id});return false;" />
formId - 您明确输入表单 ID 或使用我的 Jquery 函数
更新 - myTable.id 是表 ID(正是 div 包装器)
流程 - @all、@this、@form 等。
关于jsf - 如何访问 Composite 的父命名容器?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12090950/