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

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

问题描述

我希望能够在我的页面上的 2 个位置拥有 Primefaces 树.原因是我想让具有相同数据的两棵树具有完全相同的状态-扩展相同的节点等.我尝试将两个实例绑定到支持 bean 中的相同值,但这只会导致其中一个呈现.我做错了吗?这应该以不同的方式解决吗?

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组件绑定后消失

编辑 1

我注意到我可以使用 'value=' 轻松共享选择值,但真正的问题是共享哪些节点已展开,哪些节点已折叠.我不知道这是存储在服务器上,还是完全可以存储在服务器上.

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.

推荐答案

我尝试将两个实例绑定到支持 bean 中的相同值,但这会导致其中只有一个呈现.我做错了吗?

这绝对是错误的.每个组件 binding 都应解析为一个 unique 请求范围属性,该属性不被任何其他组件共享,也不会比请求范围更长.

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.

应该以不同的方式解决这个问题吗?

将它们绑定到不同的属性.如果您想要一个动态可扩展的属性,请使用 Map.

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).

可以用作

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

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

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