Is it ok to use a ui:repeat inside a ui:include

578 views Asked by At

We all know the difference between build time and render time. It is definitely not a great idea to put a <ui:include> tag (build time) inside a <ui:repeat> (render time), but is the opposite okay to do? Can we use <ui:repeat> inside a <ui:include>?

1

There are 1 answers

0
BalusC On

Both ways are OK.

It is definitely not a great idea to put a <ui:include> tag (build time) inside a <ui:repeat> (render time)

This is not true. You can safely do so. The only limitation is that you can't use the var of <ui:repeat> inside src of <ui:include>. In other words, the following approach will not work:

<ui:repeat value="#{bean.items}" var="item">
    <ui:include src="/WEB-INF/includes/#{item.foo}.xhtml" />
</ui:repeat>

This will only work when you replace <ui:repeat> by <c:forEach>.

But if you are not doing that, e.g.

<ui:repeat value="#{bean.items}" var="item">
    <ui:include src="/WEB-INF/includes/foo.xhtml">
        <ui:param name="foo" value="#{item.foo}" />
    </ui:include>
</ui:repeat>

Then there is no problem. Everything will work just fine.


but is the opposite okay to do? Can we use <ui:repeat> inside a <ui:include>?

You can also safely do so. If you face a problem, just press "Ask Question" button on right top.

See also: