JSF组件绑定 - 有些混乱

rap*_*apt 6 jsf binding components el jsf-2

从像这样的网页,

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

我知道JSF标记/视图组件中的绑定属性是将视图组件绑定到辅助bean中的UI组件的Java实例.

例如,这是在以下代码中完成的操作:

<h:inputText value="#{ myBean.someProperty}" binding="#{ myBean.somePropertyInputText}"/>
Run Code Online (Sandbox Code Playgroud)

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

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

id:cidtaglib函数在哪里定义如下:

public static String cid(UIComponent component) {
    FacesContext context = FacesContext.getCurrentInstance();
    return component.getClientId(context);
}
Run Code Online (Sandbox Code Playgroud)

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

那么表达式的含义是binding="#{foo}"什么?

Bal*_*usC 10

它只是将组件绑定到当前的Facelet范围.如果你根本不需要它,那么这个特别有用.这将保护您的支持bean代码免于无用的属性,这些属性根本没有在任何其他方法中使用.请注意,它在JSF 1.2中也是这样的.不确定JSF 1.0/1.1,因为它使用了不同的JSF专有EL API.

也可以看看: