Reputation: 912
Today I found out an interesting thing with tag in JSF. I got this point from a BalusC's comment:
<h:form>
<h:outputText value="#{bean.text1}" styleClass="myClass" />
<p:commandButton value="Update" update="@(.myClass)" />
</h:form>
But the following example will work (note that assigning the form an ID is not necessary):
<h:form>
<h:outputText id="myText" value="#{bean.text1}" styleClass="myClass" />
<p:commandButton value="Update" update="@(.myClass)" />
</h:form>
It seems Primefaces will not generate an ID for plain HTML tag. I tried with several components, but still not sure. So, Is my conclusion correct? If so, why is this behaviour?
Upvotes: 0
Views: 504
Reputation: 6184
Assuming you are asking why there is no ID attribute on your <span>
element rendered by <h:outputText value="#{bean.text1}" styleClass="myClass" />
:
By default, the h:outputText
component rendered by com.sun.faces.renderkit.html_basic.TextRenderer
(in case of Mojarra) does not render an ID. Whether or not an ID is rendered is determined by com.sun.faces.renderkit.html_basic.HtmlBasicRenderer.shouldWriteIdAttribute(UIComponent)
right here:
/** * @param component * the component of interest * * @return true if this renderer should render an id attribute. */ protected boolean shouldWriteIdAttribute(UIComponent component) { // By default we only write the id attribute if: // // - We have a non-auto-generated id, or... // - We have client behaviors. // // We assume that if client behaviors are present, they // may need access to the id (AjaxBehavior certainly does). String id; return (null != (id = component.getId()) && (!id.startsWith(UIViewRoot.UNIQUE_ID_PREFIX) || ((component instanceof ClientBehaviorHolder) && !((ClientBehaviorHolder) component).getClientBehaviors().isEmpty()))); }
All of this is plain JSF and does not have any relation to primefaces.
Upvotes: 3