RE: Hibernate and Tables: Unexpected Snag: DirectLink prevents access to requestCycle?

"Luke Galea" <[email protected]>
Newsgroups gmane.comp.java.tapestry.devel
Message-ID <[email protected]>
Thanks for the suggestion.. I'll give that a try. As for why I need the
session, it's actually in the call to getRowCount that is causing it..
so after the DirectLink is complete.. I am using an anonymous inner
class.. so that explains the problem. I will try your suggestion. Thanks
again.
 
Luke Galea 
Software Development
BlueCat Networks <http://www.bluecatnetworks.com/> 
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 <http://www.bluecatnetworks.com/> 
905-762-5225
 
 
  _____  

Do you Yahoo!?
Yahoo! <http://rd.yahoo.com/mail/mailsig/*http:/mailplus.yahoo.com>
Mail Plus - Powerful. Affordable. Sign up now
<http://rd.yahoo.com/mail/mailsig/*http:/mailplus.yahoo.com>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.