[Opensource] Blocks in Session

Michael Rimov rimovm at centercomp.com
Fri Feb 21 11:17:25 PST 2003


At 04:21 PM 2/21/2003 +0800, you wrote:
>Hey!
>I have a navigaion based on the rights of the user's usergroups. Now I 
>want to put this into the session, since it is not changing throughout a 
>session.
>That is my code for that:
>
>NaviHelper navHelp = new NaviHelper();
>Block navi = navHelp.navigation(someParams);
>add(navi);
>mySession.setPersistentAttribute("navBlock", navi);

-Looks good here.

Let me reiterate the 'code' just to make sure its all there.
Given ControllerRequest named request, you end up with:
request.getSession().setPersistentAttribute("navBlock",navi);




>The problem is, that it works fine in the next jsp, but I get an error in 
>the following jsps.
>My code for retrieving this is something like this:
>
><logic:iterate id="oneNavi" property="navi">
>         <bean:write name="oneNavi" property="label"/>:<br>
></logic:iterate>
>
>What I did as an workaround was something I found in DynamicCmd.java. In 
>every state I'm now checking if this persistent attribute exists. If so it 
>will be added to controller response again. Is there any possiblity to set 
>a Block into a session and get it from the session into each jsp without 
>adding it again in every state?

Well, your code looks good, however, given the stateless nature of Http, 
you're still going to want to check for the existence in each state since 
anybody can get to any state at any time.

You might want to debug it by making a HttpSessinonListener that allows you 
to figure out when Persistent Attributes are set and unset.  That might 
help you figure out why it's getting unset between requests (which it 
shouldn't be)

HTH!
                                                 -Mike







More information about the Opensource mailing list