I am trying to implement your suggestion.. but I have a couple questions.

I am sure I am having a brain freeze here.. but basically what I am getting at is I have something similar to your sql connection source object..

If I can’t store a reference to the page.. how can I access the request cycle from within that connection source object, short of reworking the whole table model to pass the request cycle all the way along? I could, of coarse, open a new session simply for this process to avoid the need for the request cycle (using a singleton sessionFactory).. but I like the way this was going, if I could find the missing piece of puzzle.

 

Thanks again for your help.

 

Luke Galea

Software Development

BlueCat Networks

905-762-5225

 

-----Original Message-----
From: Mind Bridge [mailto:[EMAIL PROTECTED]]
Sent: November 21, 2002 5:21 PM
To: Luke Galea; Tapestry Developer
Subject: Re: [Tapestry-developer] Hibernate and Tables: Unexpected Snag: DirectLink prevents access to requestCycle?

 

Hi Luke,

If I understand correctly, the method that creates the Hibernate session is invoked when the column header link is clicked upon and its listener is invoked. The listener calls that method, which in turn calls getRequestCycle(), which returns null.

A couple of observations:

- If getRequestCycle() returns null, that means that the component/page that invokes it is not currently bound to a cycle at all. This typically occurs when a reference to the component/page is kept somewhere (usually when using an inner class) and that reference is then used to perform certain actions. One thing that always has to be kept in mind, however, is that due to pooling, the component/page referred to by that reference MAY NOT BE the component/page that is used by the current cycle (in fact, if it is, it would be a mere coincidence; on a loaded system it would probably be currently used by another user; basically, a single session may be served by various different page instances, depending on which ones would happen to be free when the requests of that session come in).

In order to avoid this problem, instead of keeping a reference to the page/component, keep a ComponentAddress (net.sf.tapestry.ComponentAddress). When you need the page (in a direct listener, most likely), use the ComponentAddress to load the page for you:

address.findComponent(cycle)

An example of this procedure in the context of a Table can be found in the LocaleSelection component in the Workbench -- see tutorial.workbench.table.LocaleSelection -- have a look at how the table columns are defined there (at the end of the file) and at createColumnModel() where they are instantiated.

Please note that ComponentAddress needs to be used in many other cases, specifically every time a Direct listener is invoked within a Block or anything else related to IRender. Tsvetelin or I will probably write a more detailed email on it, since we need to use polymorphism quite heavily in our projects, and this props up very often.

- I am kind of wondering about one thing: Why is it necessary to create a Hibernate session when the sorting state is changed? Shouldn't it be created later, on demand for data? Why is the changing of the sorting state causing the creation of a session?

I hope I have understood the problem correctly, and have been helpful.

Best regards,

-mb

 

 Luke Galea <[EMAIL PROTECTED]> wrote:

Hello all.. I am nearly done the development of a HibernateTableModel (and corresponding SessionStateManagers, DataSource, etc ) for the MindBridge contrib Table component.

 

It’s looking great.. but I am having a problem: The default column component uses a DirectLink for the column header links that make the table sort by that particular column. I have extended BasePage and created DataStoreAccessingPage that can provide Hibernate sessions…

 

It works by setting an attribute in the request cycle with the open session so future requests will use the open session. During page detach the session is closed.

 

The problem is, when the DirectLink is called “getRequestCycle” returns null.. can work around this by creating a session purely for the purpose of completing the directLink.. but that isn’t very elegant. Is there some way around this? I could change the code to not use DirectLink.. but other than this problem, DirectLink is ideal.

 

Thanks in advance

 

Luke Galea

Software Development

BlueCat Networks

905-762-5225

 

 


Do you Yahoo!?
Yahoo! Mail Plus - Powerful. Affordable. Sign up now

Reply via email to