2

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 ?

Mahmoud Saleh
  • 33,303
  • 119
  • 337
  • 498

1 Answers1

6

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.

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • and to get an element by id i have to get it with the full generated id, not with it's given id, right ? – Mahmoud Saleh Nov 26 '11 at 14:52
  • 3
    In JavaScript do you mean? Of course. All which JavaScript sees and has access to is the HTML DOM tree, not the JSF component tree. JavaScript runs in webbrowser, not in webserver. JSF runs in webserver and generates HTML. – BalusC Nov 26 '11 at 14:59