JSF 组件 id 中生成的前缀 j_idt33 是什么?
我定义 h:messages 组件如下:
<h:messages id="summary" styleClass="summary" globalOnly="true"/>
但是当我用 firebug 检查元素时,我注意到 id 被转换为如下内容: j_idt33:summary
那个前缀是什么,为什么生成它?
i define h:messages component as follows:
<h:messages id="summary" styleClass="summary" globalOnly="true"/>
but when i inspected element with firebug, i noticed that the id is translated to something like: j_idt33:summary
what's that prefix, and why it's generated ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是父级
NamingContainer
组件,如
、
、
、
、复合组件等。JSF在生成的 HTML 客户端 ID 前面添加父命名容器组件的 ID,以避免在重用组件时发生 HTML 客户端 ID 冲突在生成的 HTML 输出中多次出现,例如在表行、包含文件或复合组件等中。也就是说,多个 HTML 元素具有相同的 ID 是非法的。
您可以通过为
NamingContainer
组件提供固定 ID 来抑制自动生成的 ID。在您的特定情况下,它很可能是
。因此给它一个固定的ID,例如这样
j_idt33:summary
将变成form:summary
。That's the ID of the parent
NamingContainer
component like<h:form>
,<h:dataTable>
,<ui:repeat>
,<f:subview>
, a composite component, etc.JSF prepends the generated HTML client ID with the ID of the parent namingcontainer component in order to avoid clashes in the HTML client ID whenever a component is reused more than once in the generated HTML output, such as in a table row, or an include file, or a composite component, etc. It's namely illegal to have multiple HTML elements with the same ID.
You can suppress the autogenerated ID by giving the
NamingContainer
component a fixed ID. In your particular case, it's most likely the<h:form>
. So give it a fixed ID, e.g.this way the
j_idt33:summary
will becomeform:summary
.