You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Warner Onstine <sw...@warneronstine.com> on 2004/03/27 00:35:24 UTC

another tree question

Ok, what is happening now is that when I visit the page containing the 
tree it is pulling the tree model from the session, unfortunately since 
this is db-driven (through Hibernate) it crashes the second time I view 
it because not all of the information was there the first time. Is 
there a way to force the component to pull the latest tree model each 
time I hit that page (also because once I add a category I want it to 
show there)?

-warner



---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org


Re: another tree question

Posted by Warner Onstine <sw...@warneronstine.com>.
Hi Tsetvelin, I'm getting the NPE that I referred to below in 
getSessionState(). By the way, I'm still doing this in my page:
	public void init() {
		CategoryTreeNode parent;
		value = null;
		Global global = (Global) getEngine().getGlobal();
		List categories = new Vector();
		try {
			Session sess = global.openSession();
			categories = sess.find("from Category as category where 
category.parent is null");
		} catch (HibernateException e) {
			throw new ApplicationRuntimeException(
							"There was a problem retrieving a root category - " + e);
		}
		//grab the first one as it should be the only one
		Category rootCategory = (Category) categories.get(0);
		setRootCat(rootCategory);
		parent = new CategoryTreeNode(rootCategory);
		if(rootCategory.getSubCategories().size() > 0) {
			populateNode(parent, rootCategory);
		}
		treeDataModel = new SimpleTreeDataModel(parent);
		treeModel = new SimpleTreeModel(treeDataModel);
	}

I noticed in the code you sent me that there is a ITreeStateModel that 
you are passing into the SimpleTreeModel, do I need to instantiate one 
in my Page? And if so, what do I need to do exactly?

Thanks for all the help.

-warner

On Mar 30, 2004, at 12:48 AM, tsvetelin wrote:

> Hi Warner,
>
> Could you try to use the following implementation of the
> TreeSessionStateManager. In this implementation the data model will be
> loaded every tree rendering time, but the tree session state will be 
> the
> same - the expanded node should still expanded.
>
> public Object getSessionState(ITreeModel objModel)
> {
>   return objModel.getTreeStateModel();
> }
> public ITreeModel getModel(Object arg0) {
>   ITreeDataModel treeDataModel = loadTreeDataModel();
>   ITreeStateModel treeStateModel = (ITreeStateModel)arg0;
>   ITreeModel treeModel = new SimpleTreeModel(treeDataModel,
> treeStateModel );
>   return treeModel;
> }
>
> public ITreeDataModel loadTreeDataModel(){
>   //the same code like your original getModel implementation.
>   .
>   .
>   .
> }
>
> I hope that this will work.
>
> Tsvetelin.
>
> PS. Please remove every lines where you reset the tree (with
> "TreeView.resetState()" method) when you test the above implementation.
>
>
>
> -----Original Message-----
> From: Warner Onstine [mailto:sw-list@warneronstine.com]
> Sent: Monday, March 29, 2004 9:11 PM
> To: Tapestry users
> Subject: Re: another tree question
>
>
> Alright, no matter the method I have tried to do I am now ending up
> with this problem.
>
> I can only navigate the first level of the tree nodes. As soon as I try
> to go down one more level it collapses everything and returns to just
> the top node showing. Thankfully it is now showing changed nodes on
> that page. Here are the different methods I have tried and their
> results:
> 1) Make Categories.java implement TreeStateListener and call reset in
> the TreeChanged method
> This resulted in displaying the first level one time only, afterwards
> it refused to show even the first level of nodes until I cleared the
> session from Tomcat
>
> 2) Implement my own version of SessionStateManager (see attached)
> This is where I am currently, with being able to only see the first
> level of nodes
> I implemented the getSessionState to just return the objModel that gets
> passed in as I was getting a NPE when trying to do
> objModel.getTreeStateModel()
>
> 3) NullSessionStateManager
> Same as above, can only navigate the first level of nodes
>
> 4) Call the component's reset value in pageBeginRender()
> it got reset everytime I clicked on the root and never showed me
> anything below that
>
> All help is greatly appreciated as I would really love to move past
> this so I can get the rest of what I need to do (TreeTables) done ;-).
>
> Thanks!
>
> -warner
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
>
>


---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org


RE: another tree question

Posted by tsvetelin <ts...@rushmore-digital.com>.
Hi Warner,

Could you try to use the following implementation of the
TreeSessionStateManager. In this implementation the data model will be
loaded every tree rendering time, but the tree session state will be the
same - the expanded node should still expanded.

public Object getSessionState(ITreeModel objModel)
{
  return objModel.getTreeStateModel();
}
public ITreeModel getModel(Object arg0) {
  ITreeDataModel treeDataModel = loadTreeDataModel();
  ITreeStateModel treeStateModel = (ITreeStateModel)arg0;
  ITreeModel treeModel = new SimpleTreeModel(treeDataModel,
treeStateModel );
  return treeModel;
}

public ITreeDataModel loadTreeDataModel(){
  //the same code like your original getModel implementation.
  .
  .
  .
}

I hope that this will work.

Tsvetelin.

PS. Please remove every lines where you reset the tree (with
"TreeView.resetState()" method) when you test the above implementation.



-----Original Message-----
From: Warner Onstine [mailto:sw-list@warneronstine.com]
Sent: Monday, March 29, 2004 9:11 PM
To: Tapestry users
Subject: Re: another tree question


Alright, no matter the method I have tried to do I am now ending up
with this problem.

I can only navigate the first level of the tree nodes. As soon as I try
to go down one more level it collapses everything and returns to just
the top node showing. Thankfully it is now showing changed nodes on
that page. Here are the different methods I have tried and their
results:
1) Make Categories.java implement TreeStateListener and call reset in
the TreeChanged method
This resulted in displaying the first level one time only, afterwards
it refused to show even the first level of nodes until I cleared the
session from Tomcat

2) Implement my own version of SessionStateManager (see attached)
This is where I am currently, with being able to only see the first
level of nodes
I implemented the getSessionState to just return the objModel that gets
passed in as I was getting a NPE when trying to do
objModel.getTreeStateModel()

3) NullSessionStateManager
Same as above, can only navigate the first level of nodes

4) Call the component's reset value in pageBeginRender()
it got reset everytime I clicked on the root and never showed me
anything below that

All help is greatly appreciated as I would really love to move past
this so I can get the rest of what I need to do (TreeTables) done ;-).

Thanks!

-warner


---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org


Re: another tree question

Posted by Warner Onstine <sw...@warneronstine.com>.
Alright, no matter the method I have tried to do I am now ending up 
with this problem.

I can only navigate the first level of the tree nodes. As soon as I try 
to go down one more level it collapses everything and returns to just 
the top node showing. Thankfully it is now showing changed nodes on 
that page. Here are the different methods I have tried and their 
results:
1) Make Categories.java implement TreeStateListener and call reset in 
the TreeChanged method
This resulted in displaying the first level one time only, afterwards 
it refused to show even the first level of nodes until I cleared the 
session from Tomcat

2) Implement my own version of SessionStateManager (see attached)
This is where I am currently, with being able to only see the first 
level of nodes
I implemented the getSessionState to just return the objModel that gets 
passed in as I was getting a NPE when trying to do 
objModel.getTreeStateModel()

3) NullSessionStateManager
Same as above, can only navigate the first level of nodes

4) Call the component's reset value in pageBeginRender()
it got reset everytime I clicked on the root and never showed me 
anything below that

All help is greatly appreciated as I would really love to move past 
this so I can get the rest of what I need to do (TreeTables) done ;-).

Thanks!

-warner

RE: another tree question

Posted by tsvetelin <ts...@rushmore-digital.com>.
Hi Warner,

As I see there are 2 possible ways to do this.

The first one is to reset the tree state every time when you make some
modification to the tree data structure. You can invoke the method
TreeView.resetState();
The second one is to pass a implementation of ISessionStateManager to the
TreeView component. This object determine which part of the information in
ITreeModel(tree structure - data model, tree state model) will be stored in
session. The NullSessionStateManager will not store anything in the session
so the tree model will be taken from the binding every time when the tree is
rendered. Unfortunately the tree nodes will be collapsed. At the other hand
you can implement a SessionStateManager that will store only
ITreeSessionState(expanded nodes) object in the session, but will load
ITreeDataModel.

Tsvetelin

-----Original Message-----
From: Warner Onstine [mailto:sw-list@warneronstine.com]
Sent: Saturday, March 27, 2004 1:35 AM
To: Tapestry users
Subject: another tree question


Ok, what is happening now is that when I visit the page containing the
tree it is pulling the tree model from the session, unfortunately since
this is db-driven (through Hibernate) it crashes the second time I view
it because not all of the information was there the first time. Is
there a way to force the component to pull the latest tree model each
time I hit that page (also because once I add a category I want it to
show there)?

-warner



---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org