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

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

问题描述

以下代码如何工作:

#{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?

谢谢

更新:

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 <f:xxx>-正在评估中).在视图树的渲染过程中,这是通过普通的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规范

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范围中的现有变量冲突,可以使用

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}"/>

这是更易于记录的内容.

which is more self-documenting.

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

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