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

允我心安 提交于 2020-01-06 15:18:18

问题


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:


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:

  • JSTL in JSF2 Facelets... makes sense?
  • Dynamic <ui:include src> depending on <ui:repeat var> doesn't include anything


来源:https://stackoverflow.com/questions/30905647/is-it-ok-to-use-a-uirepeat-inside-a-uiinclude

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!