< ui:param>的范围是什么?在JSF中? [英] what is the scope of <ui:param> in JSF?

查看:340
本文介绍了< ui:param>的范围是什么?在JSF中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经看到2次,以前浏览的页面中的变量会干扰或替换下游查看的页面中的变量(例如h:datatable"var").

I've seen 2 times that a variable from a page previously browsed can interfere with or replace a variable (for example a h:datatable "var") from a page viewed downstream.

那么ui:param的范围是什么?并有一种包含它的方法吗?

So what is the scope of ui:param ? And is there a way to contain it ?

推荐答案

它基本上在EL上下文中设置了一个新的变量映射.另请参见

It basically sets a new variable mapping in the EL context. See also the source code of ParamHandler:

94     public void apply(FaceletContext ctx, UIComponent parent)
95             throws IOException {
96         String nameStr = this.name.getValue(ctx);
97         ValueExpression valueVE = this.value.getValueExpression(ctx,
98                 Object.class);
99         ctx.getVariableMapper().setVariable(nameStr, valueVE);
100    }

请注意第99行(与Mojarra 2.1.0中一样).这将从EL中检索 VariableMapper上下文,然后

Note line 99 (as in Mojarra 2.1.0). This retrieves the VariableMapper from the EL context and then sets a variable mapping on it with a ValueExpression as value.

这基本上具有全局"范围.因此,如果变量名称为"foo",则在同一EL上下文(基本上是当前的HTTP请求)中引用了"foo"的每个单个EL表达式将由该值评估变量映射器中指定的表达式.它的优先级高于重复组成部分的var(如果有).因此,这确实可能导致冲突和空"的中继器.

This has basically the "global" scope. So if the variable name is "foo", then every single EL expression which is evaluated in the same EL context (basically, the current HTTP request) which ever references "foo" will be evaluated by the value expression as specified in the variable mapper. This has a higher precedence than the var of the repeating components, if any. So this may indeed lead to conflicts and "empty" looking repeaters.

最好给<ui:param><h:dataTable var>一个不同的名称.例如,您可以选择为所有<ui:param>(和<c:set>)变量加上_前缀.

Better give either the <ui:param> or the <h:dataTable var> a different name. You could for example choose to prefix all <ui:param> (and <c:set>) variables with _ or so.

这篇关于&lt; ui:param&gt;的范围是什么?在JSF中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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