如何从数据表更新面板 [英] How to update panel from datatable
问题描述
带有id("myButtonId2")的Commandbutton可以正常工作.我的意思是它更新了"myOutputPanel",但数据表中的命令按钮没有更新outputPanel.数据表是否有特定的更新样式?
Commandbutton with id("myButtonId2") works fine. I mean it updates "myOutputPanel" but commandbutton which is inside datatable doesn't update outputPanel. Is there a specific update style for datatables?
<h:form id="myForm" prependId="false">
<p:panel id="myPanel">
<p:dataTable id="myDatatable">
<p:column style="width:4%">
<p:commandButton id="myButtonId" update="myOutputPanel"/>
</p:column>
</p:dataTable>
<p:commandButton id="myButtonId2" update="myOutputPanel"/>
</p:panel>
<p:outputPanel id="myOutputPanel">
//some stuff
</p:outputPanel>
推荐答案
这是因为使用process
和update
时,它们的作用方式与f:ajax
组件属性execute
和render
几乎相同.如果它们位于同一NamingContainer
中,则只能直接引用其ID.
This is because with process
and update
they work much the same way as the f:ajax
component attributes execute
and render
do. One can only reference the id of a component directly if they reside within the same NamingContainer
.
默认情况下,clientID是通过在前缀由:
分隔的命名容器ID之前添加前缀而生成的.尽管h:form
和p:dataTable
确实实现了NamingContainer
,但p:panel
组件未实现NamingContainer
.
The clientID is generated by prefixing the naming container ids seperated by :
by default. The p:panel
component does not implement NamingContainer
although h:form
and p:dataTable
do implement NamingContainer
.
myOutputPanel
的clientID如下:
The clientID of myOutputPanel
is as follows:
myForm:myOutputPanel
第二个按钮之所以起作用,是因为它位于dataTable的外部,并且相对于myOutputPanel
在相同的NamingContainer中,该形式为表格.要在process
或update
中引用绝对的clientID,可以在clientID前面加上:
符号.
The second button works because it is outside of the dataTable and relative to myOutputPanel
in the same NamingContainer which is the form. To reference the absolute clientID in process
or update
one can prefix the clientID with the :
symbol.
尝试将第一个commandButton的update
属性更改为:
Try changing the update
attribute of the first commandButton to:
:myForm:myOutputPanel
这应该允许它绝对引用其生成的clientID和工作.
This should allow it absolutely reference its generated clientID and work.
这篇关于如何从数据表更新面板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!