我正在尝试使用 prependId 来缩短更新命令。 如果我始终使用合格的 id,一切正常。 如果我使用prependId,找不到id:
<h:form id="form">
<p:dataTable id="table">
//closing tags
<p:commandButton update=":form:table"> //works
<h:form prependId="false">
<p:dataTable id="table">
//closing tags
<p:commandButton update=":table"> //works NOT!
在 View 中找不到标识符为“:table”的组件。
我做错了什么?
最佳答案
if you want to update from outside the tags you have to use ":". and as I wrote it works with specific id's. I just want to get to know how prependId works instead...
这只有在 prependId="true"
时才是正确的。 update 属性需要一个 clientId 来更新,通过将 prependId 设置为 false,您声称该表单中的所有元素都将具有与服务器 ID 相同的 clientId。因此,正如 Jigar 在上面的评论中已经提到的,它应该只是 table
。
如果您不相信我,那么请在 Firebug 中自己尝试一下,并注意 Primefaces 数据表的最外层 div 元素的 ID 仅为 table
。无论形式如何,更新都能够找到它,因为它正在页面上寻找与它匹配的 id。
这可能很危险,因为很容易在 DOM 上意外地让具有相同 ID 的多个组件发生冲突。对于其他页面或通过包含组件、第三方或其他方式在具有内部 DOM 元素和唯一 ID 的页面上,情况更是如此。此类问题极难追踪。
关于java - JSF - prependId 不工作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9343393/