在JSF中使用绑定属性有什么优势? [英] What is the advantages of using binding attribute in JSF?

查看:77
本文介绍了在JSF中使用绑定属性有什么优势?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请参见以下代码:

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

在上面的示例中,我们使用绑定属性与服务器端bean属性进行链接.我想知道使用此属性和不使用此属性有什么区别.

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.

推荐答案

使用绑定属性,您将映射实际组件而不是组件的值.例如,示例的后备bean中的属性如下所示:

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

将组件实例绑定到Bean属性具有以下优点:

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

  • 支持bean可以通过编程方式 修改组件属性.
  • 支持bean可以实例化
    组件而不是让页面
    作者这样做.
  • The backing bean can programmatically modify component attributes.
  • The backing bean can instantiate
    components rather than let the page
    author do so.

查找更多详细信息在本教程中

这篇关于在JSF中使用绑定属性有什么优势?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆