动态< ui:include>不起作用 [英] Dynamic <ui:include> doesn't work

查看:90
本文介绍了动态< ui:include>不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想这样使用动态ui:include.

I want to use a dynamic ui:include, like this.

<ui:repeat value="#{FormsService.getTemplates(component.form)}"
                var="template">
    <ui:include src="forms/#{template.id}.xhtml"/>
</ui:repeat>

以某种方式总会导致包含"forms/.xhtml",好像#[template.id}为空. 但我知道#{template.id}不为空. IE.只是这样打印出来就可以给我期望的价值.那么,这里出了什么问题?感谢您的帮助.

Somehow this always results in an include of "forms/.xhtml", as if #[template.id} would be empty. But I know that #{template.id} is not empty. I.e. just printing it out like that gives me the expected value. So what goes wrong here? Any help is appreciated.

推荐答案

由于< ui:repeat>被实现为UIComponent,并且< ui:include>逻辑在TagHandler中.构建组件树时(例如在restoreView阶段),将添加单个UIRepeat组件,但#{template.id}不能正确评估.它不会求值,因为UIRepeat变量模板"仅在组件处理期间可用,而在树构造期间不可用.

These tags are somewhat confusing since <ui:repeat> is implemented as a UIComponent and <ui:include> logic is in the TagHandler. When component tree is built, for example in restoreView phase, a single UIRepeat component is added but #{template.id} won't evaluate properly. It won't evaluate because UIRepeat variable "template" will be available only during component processing and not during tree construction.

您有两种选择.首先是您可以使用< c:forEach>而不是< ui:repeat>.这是一个简单的解决方案,可能对您来说很好.它有一个小的缺点:如果您多次出现同一模板,则组件树将为每次出现包含模板组件的单独副本.结果,内存和CPU性能都会受到影响.

You have got two options. The first is you can use <c:forEach> instead of <ui:repeat>. This is an easy solution and probably will work fine for you. There is one minor downside to it: if you have multiple occurences of the same template, the component tree will contain a separate copy of the template components for each occurence. As a consequence both memory and CPU performance will suffer.

另一个选择是使用真正的动态包含组件.不幸的是我还没有找到一个.我设法实现了这样的组件,但这不是一个非常方便的解决方案,因为它还需要稍微修改的UIRepeat版本.我们必须采用这种方法,因为< c:forEach>会导致性能下降.对我们来说太重了.

The other option is to use a true dynamic include component. Unfortunately I haven't found one available. I managed to implement such component but it's not a very convenient solution since it also requires a slightly modified UIRepeat version. We had to go for this approach because the performance loss from <c:forEach> was too heavy for us.

这篇关于动态&lt; ui:include&gt;不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆