Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Apply JSF rendered attribute to span

Tags:

jsf

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

like image 815
user3095976 Avatar asked Mar 03 '14 21:03

user3095976


1 Answers

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>
like image 57
BalusC Avatar answered Nov 01 '22 02:11

BalusC