Look at the following code. It might give you idea and better way of doing.
Public class Visit{
// constructor.
public Visit(){
HttpSession s = (HttpSession) fCurrentSession.get();
s.setAttribute("visit", this) ;
}
// other methods and code goes here.
}//end of the Visit class.
public static Visit getVisit() {
HttpSession s = (HttpSession) fCurrentSession.get();
s.getAttribute("visit");
if(s != null)
return (Visit) e.getVisit();
return null;
}
Muralidhar Y
Software Engineer,
Adastrum technologies-Nikai groups,
EmiratesGroup-I.T Division,
Dubai, UAE.
Mobile : 00971-50-2256149.
http://www.adastrumtech.com
http://www.mercator.aero
(Keep Smiling. Be happy All The Time.)
-----Original Message-----
From: Patrick Casey [mailto:[EMAIL PROTECTED]
Sent: 27 September 2005 00:33
To: 'Tapestry users'
Subject: Better way to statically get ahold of the visit object?
Is there a better way to get ahold of the visit object
statically (e.g. without access to the cycle or page objects?). Right now
I'm using:
public static Visit getVisit() {
HttpSession s = (HttpSession) fCurrentSession.get();
Enumeration en = s.getAttributeNames();
while (en.hasMoreElements()) {
String attrib = (String)
en.nextElement();
Log.info(attrib);
if (attrib.startsWith(ENGINE_PREFIX)) {
AbstractEngine e =
(AbstractEngine) s.getAttribute(attrib);
return (Visit) e.getVisit();
}
}
return null;
}
Which is sort of messy because it requires iterating every
attribute in the session and doing string compares to find the right one. Is
there a better approach (or one that doesn't involve doing an end run around
the Tapestry Engine)?
--- Pat