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

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

问题描述

查看以下代码:

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

在上面的示例中,我们使用 binding 属性来链接服务器端 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 可以实例化
    组件而不是让页面
    作者这样做.

在本教程中了解更多详细信息

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

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