How to conditionally render plain HTML elements like s?

The right JSF component to represent a HTML <div> element is the <h:panelGroup> with the layout attribute set to block. So, this should do:

<h:panelGroup layout="block" ... rendered="#{someCondition}">
    ...
</h:panelGroup>

Alternatively, wrap it in an <ui:fragment>:

<ui:fragment rendered="#{someCondition}">
    <div>
        ...
    </div>
</ui:fragment>

Or when you’re already on JSF 2.2+, make it a passthrough element:

<div jsf:rendered="#{someCondition}">

</div>

Do note that when you’d like to ajax-update a conditionally rendered component, then you should be ajax-updating its parent component instead.

See also:

  • Alternative to ui:fragment in JSF
  • Conditional rendering of non-JSF components (plain vanilla HTML and template text)
  • Ajax update/render does not work on a component which has rendered attribute
  • Why do I need to nest a component with rendered=”#{some}” in another component when I want to ajax-update it?
  • Is it possible to update non-JSF components (plain HTML) with JSF ajax?

Leave a Comment

techhipbettruvabetnorabahisbahis forumu