I dug into the UITreeData.getDataModel code and got some more insight on
this. UITreeData is restoring the TreeState *after* getting the
TreeModel, despite the fact that the state saved from the prior tree may
no longer be applicable to the new model returned by UITreeData.getValue.
I could set TreeState.setTransient(true) to avoid the error, but then
basic expand/collapse doesn't work.
So now that I understand the problem, how do I fix it? One idea I have
is to make a new TreeModel class that ignores the subsequent
setTreeState call if I've changed the model in some way (for instance,
building a new model from a different root). I think I saw some emails
on the list about a patched TreeModel class that serves this purpose.
-- Bill
Bill Schneider wrote:
I am trying to implement a page with the tree2 tag in which clicking on
a node in the tree redraws the tree with a new root.
I have things almost working except for breakage with expansion state.
Somehow I am unable to wipe the current expansion state after building
the new tree model with the new root after selection. This often
results in an "illogical state" / "Node is expanded but it is also
considered a leaf..." error.
I am using request scope for my managed bean and client-side state
saving. My JSP looks something like this:
<t:tree2 value="#{bean.tree}" var="node" binding="theTree" ....>
<f:facet...>
<h:commandLink action="#{bean.changeRoot}"> ... </h:commandLink>
</f:facet...>
</t:tree2>
and my controller looks something like this:
public class Bean {
private HtmlTree _theTree; //+getters/setters
private TreeNode _root;
private TreeModel _model;
public TreeModel getTree() {
_model = new TreeModelBase(... data from root ...);
return _model;
}
public void changeRoot() {
TreeNode newRoot = _theTree.getNode();
_root = newRoot;
_model = new TreeModelBase(... newRoot ..);
// somehow need to wipe expansion state
_model.setTreeState(new TreeStateBase());
}
}
It seems like providing a fresh TreeStateBase object should wipe the
current expansion state but this doesn't seem to help. Any ideas for
what I might be missing here?
Thanks in advance,
-- Bill
--
Bill Schneider
Chief Architect
Vecna Technologies
5004 Lehigh Rd.
College Park, MD 20740
[EMAIL PROTECTED]
t: 240-737-1640
f: 301-699-3180