15

See the following code:

<h:inputText id="name" value="#{jsfBean.name}" binding="#{jsfBean.htmlInputText}"/>

In the above example we are using the binding attribute to link with the server side bean property. I want to know what is the difference in using this attribute and not using this attribute.

Krishna
  • 7,154
  • 16
  • 68
  • 80

1 Answers1

20

With binding attribute you are mapping the actual component and NOT the component's value. For e.g the property in backing bean for your sample looks like below

UIInput htmlInputText= null;
...
public void setHtmlInputText(UIInput userNoComponent) {
  this.userNoComponent = userNoComponent;
}
public UIInput getHtmlInputText() {
  return userNoComponent;
} 

Binding a component instance to a bean property has these advantages:

  • The backing bean can programmatically modify component attributes.
  • The backing bean can instantiate
    components rather than let the page
    author do so.

Find more details in this tutorial

Aravind Yarram
  • 78,777
  • 46
  • 231
  • 327
  • I have another doubt. Is it correct implementation in the backing bean:public HtmlInputText getHtmlInputText() { return htmlInputText; } public void setHtmlInputText(HtmlInputText htmlInputText) { this.htmlInputText = htmlInputText; } – Krishna Dec 26 '10 at 06:46
  • i believe yes. But I stick to UIInput unless you want to use the specific methods of the subclass – Aravind Yarram Dec 26 '10 at 07:01
  • is it possible to set value by using binging a component instance as in value attiribute. When component render I want to set value in backing bean. – efirat Mar 03 '16 at 14:40