JSF 组件绑定 - 一些混乱 [英] JSF component binding - some confusion

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

问题描述

来自像这样的网页,

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

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

I understand that the binding attribute in JSF tag/view component is to bind the view component to a Java instance of the UI component in the backing bean.

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

E.g., that's what is done in the following code:

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

但有时我会看到 这样的代码:

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

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

where id:cid is a taglib function which is defined as follow:

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

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

In the above code, binding="#{foo}" does not bind to "a Java instance of the UI component in the backing bean".

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

So what is the meaning of expressions such as binding="#{foo}" ?

推荐答案

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

It just binds the component to the current Facelet scope. This is particularly useful if you don't need it in the backing bean at all. This saves your backing bean code from useless properties which aren't been used in any of the other methods at all. Note that it also works that way in JSF 1.2. Not sure about JSF 1.0/1.1 though as it uses a different and JSF-proprietary EL API.

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

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