没有 bean 属性的 JSF 组件绑定
下面的代码到底是如何工作的:
#{aaa.id}
<h:inputText id="txt1" binding="#{aaa}"/>
我的意思是,通常组件绑定是通过在 bean 中指定一个属性(UIComponent 类型)来工作的。在这里,没有 bean 也没有属性,但名称“aaa”仍然被正确绑定(显示组件 id -“txt1”)。它是如何工作的/在哪里指定的?
谢谢
更新:JSF2.0 规范 [pdf](第 3.1.5 章)说:
“组件绑定是一种特殊的值表达式,可用于促进将组件实例“连接”到 JavaBean 的相应属性...指定的 ValueExpression 必须指向 UIComponent 类型的读写 JavaBeans 属性(或 适当的子类)。”
How does exactly the following code work:
#{aaa.id}
<h:inputText id="txt1" binding="#{aaa}"/>
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?
Thanks
UPDATE: The JSF2.0 Spec [pdf] (Chapter 3.1.5) says:
"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)."
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在构建视图树期间,它已被放入默认的 EL 作用域中(即所有
绑定
属性以及标记处理程序的属性,如 JSTL
和JSF
-- 正在评估)。它在视图树渲染期间通过普通 EL 方式显示。视图树的渲染发生在视图树构建之后,因此它是这样工作的。这段代码并不是像您从源代码中期望的那样“逐行”运行。我无法向您指出指定的单个参考文献,因为没有。您必须阅读 EL 规范 和 JSF 规范 单独进行 1+1=2。
顺便说一句,为了避免新开发人员感到困惑并避免与 EL 范围中的现有变量发生冲突,您可以使用
java.util.HashMap
在请求范围内,在faces-config.xml:
使用
并按如下方式 更多自我记录。
另请参阅:
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.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.
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 infaces-config.xml
:and is been used as follows
which is more self-documenting.
See also: