Binding multiple components to one instance in backing bean (Primefaces Tree)

不打扰是莪最后的温柔 提交于 2019-12-11 01:43:12

问题


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.


回答1:


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}" />


来源:https://stackoverflow.com/questions/13409444/binding-multiple-components-to-one-instance-in-backing-bean-primefaces-tree

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!