[SOLVED] Tree cannot be used dynamically

UI Components for JSF
Post Reply
tonico
Posts: 51
Joined: 22 Aug 2010, 00:15

28 Aug 2011, 17:49

The UI component org.primefaces.component.tree.Tree lacks a valueExpression based setter for the "selection" attribute. This prevents to map the selection of a node to a managed bean. Here is an example

Code: Select all

org.primefaces.component.tree.Tree uiPrimeTree = new org.primefaces.component.tree.Tree();
uiPrimeTree.setId("mytree123");
uiPrimeTree.setWidgetVar("mytree123");
uiPrimeTree.setSelectionMode("single");
uiPrimeTree.setSelection( <<<<  OBJECT >>>> );  // here is the ISSUE. It is expected an object here, but there is no "setSelectionValueExpression". 
uiPrimeTree.setVar("node");
...
For the above, pointing to an mbean TreeNode property through ...

Code: Select all

setValueExpression("selection","#{myBean.mySelectionTreeNode}")
... would not work, because it would be resolved on the spot at component creation time and the component would not be able to set the selected node back ( it would lose its reference (. What we really need is a sort of "setSelectionValueExpression" where the value expression is alive and kept to resolve the setter and getter of that property.

With the above, what happens is the following exception:

SEVERE: java.lang.NullPointerException
at org.primefaces.component.tree.Tree.processUpdates(Tree.java:318)
at javax.faces.component.UIComponentBase.processUpdates(UIComponentBase.java:1242)
at javax.faces.component.UIComponentBase.processUpdates(UIComponentBase.java:1242)
at javax.faces.component.UIComponentBase.processUpdates(UIComponentBase.java:1242)
at org.primefaces.component.tabview.TabView.processUpdates(TabView.java:257)
at javax.faces.component.UIComponentBase.processUpdates(UIComponentBase.java:1242)
at javax.faces.component.UIComponentBase.processUpdates(UIComponentBase.java:1242)
at org.primefaces.component.tabview.TabView.processUpdates(TabView.java:257)
at javax.faces.component.UIComponentBase.processUpdates(UIComponentBase.java:1242)
at javax.faces.component.UIForm.processUpdates(UIForm.java:281)
Last edited by tonico on 29 Aug 2011, 19:29, edited 1 time in total.
- Tonico
Primefaces 2.2.1 - Glassfish 3.1 - Mac OS X Lion

cagatay.civici
Prime
Posts: 18616
Joined: 05 Jan 2009, 00:21
Location: Cybertron
Contact:

29 Aug 2011, 13:16

I think you need to create a proper value expression using ExpressionFactory then set it.

Code: Select all

setValueExpression("selection", selectionVE);

tonico
Posts: 51
Joined: 22 Aug 2010, 00:15

29 Aug 2011, 19:28

Thanks ! I totally missed to realize that method. Works great.
- Tonico
Primefaces 2.2.1 - Glassfish 3.1 - Mac OS X Lion

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 47 guests