绑定多个组件以一个实例在支持bean(Primefaces树) [英] Binding multiple components to one instance in backing bean (Primefaces Tree)

查看:169
本文介绍了绑定多个组件以一个实例在支持bean(Primefaces树)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望能够有一个Primefaces树,我的网页上2个地方。原因是,我想有两棵树具有相同的数据有exacly相同述明扩展等相同的节点我试着在后台bean的两个实例相同的值绑定但这会导致只是其中之一渲染。我是不是做错了?这应该不同解决?

有关问题(略有不同的要求)指出,不应该这样做,但如果不可─应该做些什么?

JSF组件绑定后消失

修改1

我已经注意到,我可以用轻松分享选择值'value =',但真正的问题是共享哪些节点展开并正在崩溃。我不知道这是否是存储在服务器上,或者,如果它可以在所有被存储在服务器上。


解决方案

  

我试图在后台bean两个实例为相同的值绑定但这会导致仅他们中的一个呈现。我是不是做错了?


这肯定是不对的。每个组件结合应解析为一个唯一请求范围的属性,这是不以任何其他组件共享,也没有生活比请求范围更长的时间。



  

如果有这样的不同的解决?


它们绑定到不同的属性。如果你想要一个动态扩展性特性,使用地图<弦乐,UIComponent方式>

 私人地图<弦乐,UIComponent>组件=新的HashMap<弦乐,UIComponent>();//吸气剂(无必要的setter)。

其可以用作

 < X:someComponent绑定=#{} bean.components.foo/>
< X:someComponent绑定=#{} bean.components.bar​​/>
< X:someComponent绑定=#{} bean.components.baz/>

I want to be able to have a Primefaces tree in 2 places on my page. The reason is that I want to have the two trees with the same data have exacly the same state- the same nodes expanded etc. I tried to bind both instances to the same value in backing bean but this results in only one of them rendering. Am I doing it wrong? Should this be solved differently?

The related question (with slightly different requirements) states that one should not do this, but if not- what should be done?

JSF component disappears after binding

Edit 1

I have noticed that I can share the selection value easily with the 'value=', but the real problem is sharing which nodes are expanded and which are collapsed. I do not know if this is stored on the server, or if it can be stored on the server at all.

解决方案

I tried to bind both instances to the same value in backing bean but this results in only one of them rendering. Am I doing it wrong?

This is definitely wrong. Each component binding should resolve to an unique request scoped property which is not shared by any other component, nor lives longer than the request scope.


Should this be solved differently?

Bind them to different properties. If you want a dynamically expansible property, use a Map<String, UIComponent>.

private Map<String, UIComponent> components = new HashMap<String, UIComponent>();

// Getter (no setter necessary).

which can be used as

<x:someComponent binding="#{bean.components.foo}" />
<x:someComponent binding="#{bean.components.bar}" />
<x:someComponent binding="#{bean.components.baz}" />

这篇关于绑定多个组件以一个实例在支持bean(Primefaces树)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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