This is a known problem with the current version of VelocityTools: the
session is not yet created at the time $session is initialized, and
remains null afterwards even if the session is later created.

Try using $request.session instead of just $session if you are sure that
the session does exist, or event $request.getSession(true) -which should
never fail- otherwise.


  Claude

Le mercredi 28 février 2007 à 18:18 +0000, Townson, Chris a écrit :
> Hi,
> 
> We've been experiencing some slightly strange behaviour attempting to access 
> the session object in the velocity context (i.e. from templates) using 
> velocity tools 1.3.
> 
> We kept finding that $session was null.
> 
> As part of our attempts to debug the problem, we basically set-up a tiny app 
> which was an exact mimic of the simple.war example web app (where we found 
> that $session was working fine).
> 
> The only difference between our minimal app and simple.war was that we used 
> velocity 1.5beta2
> 
> We continued to encounter problems in our own minimal application _until_ we 
> added a toolbox with a session scoped tool.
> 
> This seems very strange as I believe $session should be available regardless 
> when using VelocityView?
> 
> Has anyone got any ideas as to why we might be experiencing this problem?
> 
> It was noticable that we could not replicate this effect in simple.war (i.e. 
> commenting/uncommenting the "map tool" there did not affect access to 
> $session)
> 
> Below is the deployment descriptor, toolbox, and list of jars used to create 
> our copy of simple.war.
> 
> Cheers,
> 
> Chris
> 
> -- web.xml --
> 
> <?xml version="1.0" encoding="utf-8"?>
> <!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 
> 2.2//EN" 
>     "http://java.sun.com/j2ee/dtds/web-app_2_2.dtd";>
> <web-app>
> 
>     <servlet>
>         <servlet-name>velocity</servlet-name>
>         
> <servlet-class>org.apache.velocity.tools.view.servlet.VelocityViewServlet</servlet-class>
>     </servlet>
> 
>     <servlet-mapping>
>         <servlet-name>velocity</servlet-name>
>         <url-pattern>*.vm</url-pattern>
>     </servlet-mapping>
> 
>     <welcome-file-list>
>         <welcome-file>index.vm</welcome-file>
>     </welcome-file-list>
> 
> </web-app>
> 
> 
> -- toolbox.xml --
> 
> <?xml version="1.0"?>
> <toolbox>
>     <xhtml>true</xhtml>
>     <data type="number">
>         <key>velocityVersion</key>
>         <value>1.5</value>
>     </data>
>     <data type="number">
>         <key>velocityToolsVersion</key>
>         <value>1.3</value>
>     </data>
>     <data type="boolean">
>         <key>booleanTestValue</key>
>         <value>true</value>
>     </data>
>     <data type="string">
>         <key>applicationName</key>
>         <value>Lenin 0.1-alpha</value>
>     </data>
>     <!--
>     If you comment/uncomment the map tool, 
>     access to $session should toggle off/on
>     -->
>     <tool>
>         <key>map</key>
>         <scope>session</scope>
>         <class>java.util.HashMap</class>
>     </tool>
>     <tool>
>         <key>date</key>
>         <scope>application</scope>
>         <class>org.apache.velocity.tools.generic.DateTool</class>
>     </tool>
> </toolbox>
> 
> -- jars --
> 
> commons-beanutils-1.7.0
> commons-collections-3.2
> commons-digester-1.8
> commons-lang-2.2
> commons-logging-1.1
> oro-2.0.8
> velocity-1.5beta2
> velocity-tools-view-1.3
> 
> ********************************************************************************
>    
> DISCLAIMER: This e-mail is confidential and should not be used by anyone who 
> is
> not the original intended recipient. If you have received this e-mail in error
> please inform the sender and delete it from your mailbox or any other storage
> mechanism. Neither Macmillan Publishers Limited nor any of its agents accept
> liability for any statements made which are clearly the sender's own and not
> expressly made on behalf of Macmillan Publishers Limited or one of its agents.
> Please note that neither Macmillan Publishers Limited nor any of its agents
> accept any responsibility for viruses that may be contained in this e-mail or
> its attachments and it is your responsibility to scan the e-mail and 
> attachments (if any). No contracts may be concluded on behalf of Macmillan 
> Publishers Limited or its agents by means of e-mail communication. Macmillan 
> Publishers Limited Registered in England and Wales with registered number 
> 785998 
> Registered Office Brunel Road, Houndmills, Basingstoke RG21 6XS   
> ********************************************************************************


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to