JSF 组件 id 中生成的前缀 j_idt33 是什么?

发布于 2024-12-18 04:28:29 字数 225 浏览 2 评论 0原文

我定义 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

零度℉ 2024-12-25 04:28:29

这是父级 NamingContainer 组件,如 、复合组件等。JSF

在生成的 HTML 客户端 ID 前面添加父命名容器组件的 ID,以避免在重用组件时发生 HTML 客户端 ID 冲突在生成的 HTML 输出中多次出现,例如在表行、包含文件或复合组件等中。也就是说,多个 HTML 元素具有相同的 ID 是非法的。

您可以通过为 NamingContainer 组件提供固定 ID 来抑制自动生成的 ID。在您的特定情况下,它很可能是 。因此给它一个固定的ID,例如

<h:form id="form">
    ...

这样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.

<h:form id="form">
    ...

this way the j_idt33:summary will become form:summary.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文