Mahmoud Saleh
Mahmoud Saleh

Reputation: 33635

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

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 ?

Upvotes: 2

Views: 2332

Answers (1)

BalusC
BalusC

Reputation: 1109865

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.

Upvotes: 6

Related Questions