【问题标题】:JSF component binding - some confusionJSF 组件绑定 - 一些混乱
【发布时间】:2012-04-13 08:15:50
【问题描述】:

来自像这样的网页,

http://www.jsftutorials.net/components/step5.html

我了解JSF标签/视图组件中的绑定属性是将视图组件绑定到后台bean中UI组件的Java实例。

例如,下面的代码就是这样做的:

<h:inputText value="#{ myBean.someProperty}" binding="#{ myBean.somePropertyInputText}"/>

但有时我看到code like this

<h:commandButton id="t1" binding="#{foo}" value="Hello, World!" onclick="alert('I am #{id:cid(foo)}'); return false;" />

其中id:cid是一个taglib函数,定义如下:

public static String cid(UIComponent component) {
    FacesContext context = FacesContext.getCurrentInstance();
    return component.getClientId(context);
}

在上面的代码中,binding="#{foo}" 没有绑定到“支持 bean 中 UI 组件的 Java 实例”。

那么binding="#{foo}"这样的表达是什么意思呢?

【问题讨论】:

    标签: jsf binding jsf-2 components el


    【解决方案1】:

    它只是将组件绑定到当前的 Facelet 范围。如果您在 backing bean 中根本不需要它,这将特别有用。这将您的支持 bean 代码从根本没有在任何其他方法中使用的无用属性中保存下来。请注意,它在 JSF 1.2 中也以这种方式工作。不确定 JSF 1.0/1.1,因为它使用不同的 JSF 专有的 EL API。

    另见:

    【讨论】:

    • 非常感谢您的回答以及您在附加链接中的回答!这是非常有帮助和信息量的。
    猜你喜欢
    • 2014-09-24
    • 2014-03-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-06-12
    • 1970-01-01
    相关资源
    最近更新 更多