1

I am wondering which is more effective/readable etc for jsf, conditionally including or deciding inside the include whether to render the content.

e.g. conditional include

<h:panelGroup rendered="#{entitiy.condition}">
    <ui:include src="included.xml">
         <ui:param name="entity" value="#{entity}" />
    </ui:include>
</h:panelGroup>

vs always include

    <ui:include src="included.xml" />
        <ui:param name="entity" value="#{entity}" />
    </ui:include>

and then inside included.xml:

<h:panelGroup rendered="#{entity.condition}">
    <h:outputText value="#{entity.name}" />
</h:panelGroup>
Ashish Mathew
  • 783
  • 5
  • 20
KameeCoding
  • 693
  • 2
  • 9
  • 27

1 Answers1

0

IMHO conditional include feels more natural:

if condition then
  do something

I am not sure if this is really better but use c:if for the check as this would totally remove the code evaluation. See JSTL in JSF2 Facelets... makes sense?

h:panelGroup adds a span while c:if is pure render logic.

Christophe Roussy
  • 16,299
  • 4
  • 85
  • 85
  • what about if there are multiple includes after each other and only one is rendered based on the entity type and the whole things is in a DataTable with multiple entities of different types, so for each row a different include is rendered? from what I read here: https://stackoverflow.com/questions/3342984/jstl-in-jsf2-facelets-makes-sense c:if seems like a better option – KameeCoding Feb 08 '18 at 08:49
  • Well I am pretty much the only one answering and bringing up the existence of `c:if` and I get `-1` for that ... without any explanation. This keeps happening lately and it is very annoying. So please the person with a better answer, write it and teach me. – Christophe Roussy Feb 12 '18 at 08:41