conversation problem with tree
milesif Jan 14, 2008 6:34 AMHi everybody,
I deployed my application as a .war in jboss 4.2.1.
I would like to have a tree bound to a conversation to have the tree model saved in the conversation so that:
1. queries are not repeated each time I expand/collapse a node already expanded/collapsed by calling @OneToMany properties of the entities beans used by my tree model
2. when I select a node a method of a bean within the same conversation is called.
Now each ajax interaction gets a new conversation and I would like to have only one.
My page is
<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
xmlns:s="http://jboss.com/products/seam/taglib"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:rich="http://richfaces.org/rich"
template="../../layout/template.xhtml">
<ui:define name="body">
<rich:panel>
<div style="width: 300px;height: 300px; overflow: scroll;">
<h:form>
<rich:tree switchType="ajax" nodeSelectListener="#{geoStructureTreeManager.processSelection}"
ajaxSubmitSelection="true" ajaxSingle="true" ignoreDupResponses="true" reRender="sel"
binding="#{geoStructureTreeManager.tree}" >
<rich:treeNodesAdaptor id="country" nodes="#{geoStructureTreeManager.rootNodes}" var="country">
<rich:treeNode>
<h:commandLink action="#{geoStructureTreeManager.click}" value="#{country.name}" />
</rich:treeNode>
<rich:recursiveTreeNodesAdaptor id="geographicStructureAdaptor" roots="#{country.geographicStructures}"
nodes="#{geographicStructure.childrenList}" var="geographicStructure">
<rich:treeNode >
<h:outputText value="#{geographicStructure.name} #{conversation.id}" />
</rich:treeNode>
</rich:recursiveTreeNodesAdaptor>
</rich:treeNodesAdaptor>
</rich:tree>
</h:form>
</div>
<h:outputText id="sel" value="#{geoStructureTreeManager.name}" />
</rich:panel>
</ui:define>
</ui:composition>
and my bean
@Scope(ScopeType.CONVERSATION)
@Name("geoStructureTreeManager")
public class GeoStructureTreeManager {
@In
protected FacesMessages facesMessages;
@In
private EntityManager entityManager;
private HtmlTree tree;
private TreeState treeState;
@DataModel
private List<Country> rootNodes;
public String click() {
System.out.println("bombolame");
return "";
}
public void processSelection(NodeSelectedEvent event) {
System.out.println("SELECTED");
UITree tree = (UITree) event.getComponent();
System.out.println(tree);
GeographicStructure geoStructure = (GeographicStructure) tree.getRowData();
System.out.println(geoStructure.getName());
name = geoStructure.getName();
System.out.println("Conversation=" + Conversation.instance().getId());
}
public List<Country> getRootNodes() {
if(rootNodes == null) {
Query qry = entityManager.createQuery("from Country c order by c.name");
rootNodes = qry.getResultList();
}
return rootNodes;
}
private String name = "";
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public HtmlTree getTree() {
if(tree == null)
tree = new HtmlTree();
return tree;
}
public void setTree(HtmlTree tree) {
this.tree = tree;
}
public TreeState getTreeState() {
return treeState;
}
public void setTreeState(TreeState treeState) {
this.treeState = treeState;
}
}
when I expand a root node I get the following error (the binding seems not to work because the conversation is not found).
11:45:53,493 WARN [lifecycle] executePhase(RESTORE_VIEW 1,com.sun.faces.context.FacesContextImpl@1be496b) threw exception
javax.el.PropertyNotFoundException: /protected/geo/geo_structure_tree.xhtml @24,48 binding="#{geoStructureTreeManager.tree}": Target Unreachable, identifier 'geoStructureTreeManager' resolved to null
at com.sun.facelets.el.TagValueExpression.setValue(TagValueExpression.java:95)
at com.sun.faces.lifecycle.RestoreViewPhase.doPerComponentActions(RestoreViewPhase.java:244)
I tried to inject the tree in the conversation as suggested in http://www.jboss.com/index.html?module=bb&op=viewtopic&t=116956: I have no more errors but nothing happens.
I also tried to use componentState as suggested by http://www.jboss.com/index.html?module=bb&op=viewtopic&t=119410, but it did not work either: there are no errors but when I try to expand a node,it does not expand.
What I would like to do is to have a conversation to edit my tree adding, modifying and deleting its nodes.
I do not understand what's going on.
Any idea, please? What should I do to keep my tree model in the conversation and call the same conversation when selecting a different node?
Thanks in advance for your help and I apologize for the long post.......
ciao FRancesco