Resolving facelets components at runtime

do you know a way to select a different facelets component at runtime?

I’ve got some of code similar to this:

<s:fragment rendered="#{r== 'case1'}">
           <ui:include src="case1.xhtml" />
 <s:fragment rendered="#{r== 'case2'}">
            <ui:include src="case2.xhtml" />

I’d like to write

<ui:include src="#{r}.xhtml" />



Your solution should work OK – the src attribute can be a literal or an EL expression. You might want to make the expression use a managed bean property or resolve it through a function. That way, you can ensure that it is never null (you could return a reference to an empty page if it was). You’ll probably get a 404 error if #{r} resolves to null.

<ui:include src="#{myfn:resolveNotNull(r, 'pageIfRIsNull')}.xhtml" />

Leave a Reply

Your email address will not be published. Required fields are marked *