问题描述
我将h:messages组件定义如下:
i define h:messages component as follows:
<h:messages id="summary" styleClass="summary" globalOnly="true"/>
但是当我用萤火虫检查元素时,我注意到id转换为类似以下内容:j_idt33:summary
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 ?
推荐答案
这是父级的ID NamingContainer
组件,例如<h:form>
,<h:dataTable>
,<ui:repeat>
,<f:subview>
,复合组件等.
That's the ID of the parent NamingContainer
component like <h:form>
, <h:dataTable>
, <ui:repeat>
, <f:subview>
, a composite component, etc.
JSF在生成的HTML客户机ID之前加上父namingcontainer组件的ID,以避免每当在生成的HTML输出中(例如在表行中)多次重复使用组件时,HTML客户机ID发生冲突.包含文件或复合组件等.拥有多个具有相同ID的HTML元素即是违法的.
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.
您可以通过为NamingContainer
组件提供固定的ID来抑制自动生成的ID.在您的特定情况下,很可能是<h:form>
.因此,给它一个固定的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">
...
这样,j_idt33:summary
将变为form:summary
.
这篇关于JSF组件ID中生成的前缀j_idt33是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!