什么是组件在JSF绑定?当preferred被使用? [英] What is component binding in JSF? When it is preferred to be used?
问题描述
我看了一下成分与绑定在下列问题结合
属性:
据我所知,它结合了JSF标签背后的UI组件在视图中的辅助bean的 UIComponent
属性。不过,我很困惑使用组件绑定的是什么,我们应该使用它。有人可以解释它以更简单的方式,让一些实际的例子?
您应该,如果你想有机会获得的全部的 的第二个问题,你发现,<一个href=\"http://stackoverflow.com/questions/12474004/component-binding-vs-findcomponent-when-to-use-which/12477407\">component结合VS findComponent() - 时使用的 UIComponent
而不是仅仅只有它的价值。例如,要访问的一些方法不能被调用/视图中的约束。 - 有些混乱 JSF组件绑定:这是你找到了第一个问题的回答p>结合
与 findComponent()
的,没有回答的结合
与值
在所有的你似乎认为。请不要误会这个困惑。的 值
的显然赢得的 结合
的
在现实世界中code,组件绑定到后台bean通常只用于每当开发者需要通过例如编程方式操作它的孩子 component.getChildren()。添加(...)
。这个bean然而应请求范围。更广的范围可能会导致为组件实例基本上都是基于每个请求的基础上创建的,不应该跨多个请求共享inconsitenties。该视图的范围也可以,但是这是非常低效的内存,并且比旧的2.1.18版本Mojarra,部分保存状态也必须关闭,否则视图范围bean实例由引用的结合
将隐含在每次请求重新创建。参见<一个href=\"http://stackoverflow.com/questions/3342984/jstl-in-jsf2-facelets-makes-sense/3343681#3343681\">JSTL在JSF2 Facelets的......有道理?获取相关答案。
也有可能将组件绑定到视图。例如。
&LT; H:someComponent绑定=#{}一些&GT;
这是指在一个facelet范围(页面范围)的 UIComponent
的实例。这使您可以使用,例如#{some.clientId}
,#{some.value}
在同其他地方页。请注意,没有人支持bean这里所涉及。另请参见 JSF组件,而不bean属性结合。
下面是一些真实世界的电器使用结合
属性:
- disabling通过第一个文本框 的ajax的数据验证后,第二个文本字段
- 检查其形式有错误
- Input基于下拉列表中选择文本验证
- How让验证依赖于pressed按钮?
- How要实现行编号为H:dataTable的
- Split java.util.Date超过两个H:inputText的领域重新presenting小时和分钟以f:convertDateTime
I have read about component binding with binding
attribute in following questions:
I understand that it binds the UI component behind the JSF tag in the view to an UIComponent
property in the backing bean. However, I am confused what the use of component binding is and when we should use it. Can someone explain it in a more simpler way and give some practical examples?
You should use it if you want to have access to the entire UIComponent
instead of just only its value. For example, to access some methods which can't be invoked/bound in the view. This is answered in the 1st question you found: JSF component binding - some confusion
The 2nd question which you found, component binding vs findComponent() - when to use which?, merely answers "binding
versus findComponent()
", it does not answer "binding
versus value
" at all as you seem to think. Please don't get confused by this. value
would obviously win over binding
.
In real world code, component binding to the backing bean is often only used whenever the developer needs to manipulate its children programmatically by e.g. component.getChildren().add(...)
. The bean should however be request scoped. A broader scope may lead to inconsitenties as component instances are basically created on a per-request basis and shouldn't be shared across multiple requests. The view scope can also, but this is very memory inefficient, and on Mojarra versions older than 2.1.18, partial state saving must also be turned off, otherwise the view scoped bean instance referenced by binding
will implicitly be recreated on every request. See also JSTL in JSF2 Facelets... makes sense? for a related answer.
It's also possible to bind the component to "the view". E.g.
<h:someComponent binding="#{some}">
This refers to an instance of UIComponent
in the Facelet scope ("page scope"). This enables you to use for example #{some.clientId}
, #{some.value}
elsewhere in the same page. Note that no one backing bean is involved here. See also JSF component binding without bean property.
Here are some real world use appliances of binding
attribute:
- disabling second text field after data validation through ajax of first text field
- Check which form has an error
- Input text validation based on drop-down list selection
- How to let validation depend on the pressed button?
- How to implement row numbering into h:dataTable
- Split java.util.Date over two h:inputText fields representing hour and minute with f:convertDateTime
这篇关于什么是组件在JSF绑定?当preferred被使用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!