Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JSF component binding - some confusion

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

like image 645
rapt Avatar asked Mar 29 '12 16:03

rapt


1 Answers

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
like image 100
BalusC Avatar answered Nov 09 '22 00:11

BalusC