What is the advantages of using binding attribute in JSF? [duplicate]

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.


Solution 1:

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