tree component: conversation problem
nico.ben Jan 18, 2008 5:46 AMHi,
I am experimenting richfaces components with seam (2.0.0GA) and (jboss-4.2.2.GA), using the source code from richfaces demo site.
I get the following error:
11:28:16,213 WARN [lifecycle] executePhase(RESTORE_VIEW 1,com.sun.faces.context.FacesContextImpl@4e9d18) threw exception
javax.el.PropertyNotFoundException: /tree.xhtml @21,18 binding="#{simpleTreeBean.tree}": Target Unreachable, identifier 'simpleTreeBean' resolved to null
at com.sun.facelets.el.TagValueExpression.setValue(TagValueExpression.java:95)
at com.sun.faces.lifecycle.RestoreViewPhase.doPerComponentActions(RestoreViewPhase.java:244)
at com.sun.faces.lifecycle.RestoreViewPhase.doPerComponentActions(RestoreViewPhase.java:249)
at com.sun.faces.lifecycle.RestoreViewPhase.doPerComponentActions(RestoreViewPhase.java:249)
at com.sun.faces.lifecycle.RestoreViewPhase.doPerComponentActions(RestoreViewPhase.java:249)
at com.sun.faces.lifecycle.RestoreViewPhase.execute(RestoreViewPhase.java:193)
My bean is (please note the CONVERSATIONAL scope):
import [...] @Scope(ScopeType.CONVERSATION) @Name("simpleTreeBean") public class SimpleTreeBean { @In(required=false) private EntityManager entityManager; private TreeNode rootNode = null; private String nodeTitle; private static final String DATA_PATH = "/home/nicola/simple-tree-data.properties"; private void addNodes(String path, TreeNode node, Properties properties) { boolean end = false; int counter = 1; while (!end) { String key = path != null ? path + '.' + counter : String.valueOf(counter); String value = properties.getProperty(key); if (value != null) { TreeNodeImpl nodeImpl = new TreeNodeImpl(); nodeImpl.setData(value); node.addChild(new Integer(counter), nodeImpl); addNodes(key, nodeImpl, properties); counter++; } else { end = true; } } } private void loadTree() { FacesContext facesContext = FacesContext.getCurrentInstance(); ExternalContext externalContext = facesContext.getExternalContext(); InputStream dataStream = null; try { dataStream = new FileInputStream(DATA_PATH); Properties properties = new Properties(); properties.load(dataStream); rootNode = new TreeNodeImpl(); addNodes(null, rootNode, properties); } catch (Exception e) { e.printStackTrace(); throw new FacesException(e.getMessage(), e); } finally { if (dataStream != null) { try { dataStream.close(); } catch (IOException e) { externalContext.log(e.getMessage(), e); } } } } public TreeNode getTreeNode() { if (rootNode == null) { loadTree(); } return rootNode; } public void processSelection(NodeSelectedEvent event) { UITree tree = (UITree) event.getComponent(); nodeTitle = (String) tree.getRowData(); List<UIComponent> childrens = tree.getChildren(); System.out.println("----------------START----------------"); System.out.println(tree.getTreeNode()); System.out.println(tree.getData()); printTree(childrens); System.out.println("----------------END------------------"); } private void printTree(List<UIComponent> childrens) { if(childrens == null) return; for (UIComponent component : childrens) { System.out.println(component); printTree(component.getChildren()); } } public String getNodeTitle() { return nodeTitle; } public void setNodeTitle(String nodeTitle) { this.nodeTitle = nodeTitle; } private UITree tree; public UITree getTree() { return tree; } public void setTree(UITree tree) { this.tree = tree; } public static void main(String[] args) { } }
The tree page is very simple:
<ui:composition xmlns="http://www.w3.org/1999/xhtml" xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:h="http://java.sun.com/jsf/html" xmlns:f="http://java.sun.com/jsf/core" xmlns:a4j="http://richfaces.org/a4j" xmlns:rich="http://richfaces.org/rich"> <style> .col, .col2 { width:50%; vertical-align:top; } </style> <h:form> <h:panelGrid columns="2" width="100%" columnClasses="col1,col2"> <rich:tree style="width:300px" nodeSelectListener="#{simpleTreeBean.processSelection}" reRender="selectedNode" ajaxSubmitSelection="true" switchType="ajax" value="#{simpleTreeBean.treeNode}" var="item" binding="#{simpleTreeBean.tree}" > </rich:tree> <h:outputText escape="false" value="Selected Node: #{simpleTreeBean.nodeTitle}" id="selectedNode" /> </h:panelGrid> </h:form> </ui:composition>