问题
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