What's the generated prefix j_idt33 in JSF component id?

夙愿已清 提交于 2019-12-12 21:25:01

问题


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 ?


回答1:


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.



来源:https://stackoverflow.com/questions/8279189/whats-the-generated-prefix-j-idt33-in-jsf-component-id

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!