user3095976
user3095976

Reputation: 135

Apply JSF rendered attribute to span

I am trying to apply a JSF rendered attribute to a span within an h:panelGroup but the span still renders - below is some sample code I am using.

<span id="myId" rendered="#{myBean.rendered}" class="groupBox" style="left: 1px; top: 8px; height: 38px; width: 339px;"  />

Thanks

Upvotes: 5

Views: 16397

Answers (2)

blackwolf
blackwolf

Reputation: 1

You can use this as well:

<p:outputPanel style="display:block">
</p:outputPanel>

Ref: https://forum.primefaces.org/viewtopic.php?t=723

Upvotes: -1

BalusC
BalusC

Reputation: 1108742

The rendered attribute is only recognized by JSF components, not by plain HTML elements.

The JSF equivalent of the desired code can be represented by <h:panelGroup> or <h:outputText>. Both generate a HTML <span> element. If you need a <span> without text content, exactly like as in your question, just use <h:panelGroup>.

<h:panelGroup id="myId" rendered="#{myBean.rendered}" styleClass="groupBox" style="left: 1px; top: 8px; height: 38px; width: 339px;" />

If you need a <span> with text content, use <h:outputText>. You can specify the text content in its value attribute.

Alternatively, if you really, really need to write down a plain HTML <span> element yourself for some reason, then you can always move the rendered attribute to an <ui:fragment> which wraps the entire HTML content.

<ui:fragment rendered="#{myBean.rendered}">
    <span id="myId" class="groupBox" style="left: 1px; top: 8px; height: 38px; width: 339px;" />
</ui:fragment>

Upvotes: 14

Related Questions