没有 bean 属性的 JSF 组件绑定 [英] JSF component binding without bean property

查看:24
本文介绍了没有 bean 属性的 JSF 组件绑定的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下代码究竟是如何工作的:

How does exactly the following code work:

#{aaa.id}
<h:inputText id="txt1" binding="#{aaa}"/>

我的意思是,通常组件绑定是通过在 bean 中指定一个属性(UIComponent 类型)来工作的.在这里,没有 bean 或属性,但名称aaa"得到正确绑定(显示组件 ID -txt1").它是如何工作的/在哪里指定的?

I mean, usually the component binding works, by specifying a property (of type UIComponent) in a bean. Here, there's no bean nor property but nevertheless the name "aaa" gets bound correctly (displaying the component id - "txt1"). How does it work/where is it specified?

谢谢

更新:JSF2.0 规范 [pdf](第 3.1.5 章)说:

UPDATE: The JSF2.0 Spec [pdf] (Chapter 3.1.5) says:

"组件绑定是一种特殊的值表达式,可用于促进将组件实例连接"到JavaBean 的相应属性...指定的 ValueExpression 必须指向 UIComponent 类型的读写 JavaBeans 属性(或适当的子类)."

"A component binding is a special value expression that can be used to facilitate "wiring up" a component instance to a corresponding property of a JavaBean... The specified ValueExpression must point to a read-write JavaBeans property of type UIComponent (or appropriate subclass)."

推荐答案

在构建视图树的过程中,它被放入了默认的 EL 作用域中(也就是所有 binding 属性——以及标签的属性)处理程序如 JSTL 和 JSF -- 正在评估).它在视图树的渲染过程中通过普通 EL 方式显示.视图树的渲染发生在 视图树构建之后,所以它是这样工作的.并不是这段代码一行一行"运行.正如您所期望的那样.

It's been put in the default EL scope during building of the view tree (that's when all binding attributes -- and attributes of tag handlers like JSTL <c:xxx> and JSF <f:xxx> -- are being evaluated). It's being shown by normal EL means during rendering of the view tree. Rendering of the view tree happens after building of the view tree, so it works that way. It's not that this code runs "line by line" as you seemed to expect from the source.

我无法向您指出已指定的单个参考,因为没有.您必须阅读 EL 规范JSF 规范 单独做一个 1+1=2.

I can't point you out a single reference where it's been specified as there is none. You'd have to read both the EL spec and JSF spec separately and do a 1+1=2.

顺便说一下,为了避免新开发人员之间的混淆并避免与 EL 范围内的现有变量发生冲突,您可以使用 java.util.HashMapfaces-config中声明如下.xml:

By the way, to avoid confusion among new developers and to avoid clashes with existing variables in the EL scopes, you can use a java.util.HashMap in the request scope which is been declared as follows in faces-config.xml:

<managed-bean>
    <description>Holder of all component bindings.</description>
    <managed-bean-name>components</managed-bean-name>
    <managed-bean-class>java.util.HashMap</managed-bean-class>
    <managed-bean-scope>request</managed-bean-scope>
</managed-bean>

并使用如下

#{components.aaa.id}
<h:inputText id="txt1" binding="#{components.aaa}"/>

这是更多的自我记录.

这篇关于没有 bean 属性的 JSF 组件绑定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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