Reputation: 2393
I d like to implement a new page in JSF 2.2 using HTML5 syntax.
My question: How can I achieve that a specific HTML element won't be rendered if jsf:rendered evaluates to false?
Sample:
<span class="msnumber" jsf:id="msnumber" jsf:rendered="#{!empty controller.msnumber}">[#{controller.msnumber}]</span>
Do i need to use a h:outputText for this purpose? I would appreciate it, if I could use the HTML elements directly.
Greets Marc
Upvotes: 1
Views: 2077
Reputation: 1595
Your approach with the span
as pass-through element should definitely work. I tried it in one of my JSF 2.2 projects and it works as intended with MyFaces 2.2.3 and Mojarra 2.2.6.
Do you use MyFaces or Mojarra? Which version? Try to use the most current one. HTML5 support is quite new and there are bugs in older versions of MyFaces and Mojarra.
Another possibility is, that there is something wrong with your EL expression #{!empty controller.msnumber}
.
Upvotes: 1
Reputation: 31649
There's nothing wrong in using HTML syntax into facelets directly. If you want to control it being rendered or not, your best is to use the <ui:fragment />
tag, which doesn't render anything by itself:
<ui:fragment rendered="#{!empty controller.msnumber}">
<span class="msnumber" id="msnumber">[#{controller.msnumber}]</span>
</ui:fragment>
Will render just
<span class="msnumber" id="msnumber">xx</span>
in case of #{!empty controller.msnumber}
evaluating to true
.
Regarding to the way you want to achieve it, I'm not sure about adding JSF component specific attributes to HTML tags directly (although being possible the other way). Honestly I've never seen that.
Upvotes: 1