JSF component binding - some confusion

核能气质少年 提交于 2019-12-07 02:23:12

问题


From web pages like this one,

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

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

But sometimes I see code like this:

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

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);
}

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

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


回答1:


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.

See also:

  • JSF component binding without bean property


来源:https://stackoverflow.com/questions/9929518/jsf-component-binding-some-confusion

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!