|
|
Exposing Velocity generic tool results in NullPointer
I'm trying to expose Velocity's generic ListTool...
When i add a toolbox config location to the ViewResolver, however, i get the following nullpointer:Code:
java.lang.NullPointerException
at org..web.servlet.view.velocity.VelocityToolboxView.createVelocityContext(VelocityToolboxView.java:106)
My ViewResolver configuration;
Code:
lt;!-- view resolver --gt;
lt;bean id=quot;viewResolverquot;
class=quot;org..web.servlet.view.velocity.VelocityViewResolverquot;gt;
lt;property name=quot;viewClassquot;gt;
lt;valuegt;
org..web.servlet.view.velocity.VelocityView
lt;/valuegt;
lt;/propertygt;
lt;property name=quot;toolboxConfigLocationquot;gt;
lt;valuegt;
/WEB-INF/toolbox.xml
lt;/valuegt;
lt;/propertygt;
lt;property name=quot;prefixquot;gt;
lt;valuegt;/velocity/lt;/valuegt;
lt;/propertygt;
lt;property name=quot;suffixquot;gt;
lt;valuegt;.vmlt;/valuegt;
lt;/propertygt;
lt;property name=quot;exposeSpringMacroHelpersquot;gt;
lt;valuegt;truelt;/valuegt;
lt;/propertygt;
lt;/beangt;
My toolbox XML:
Code:
lt;?xml version=quot;1.0quot;?gt;
lt;toolboxgt;lt;toolgt; lt;keygt;listlt;/keygt; lt;scopegt;applicationlt;/scopegt; lt;classgt;org.apache.velocity.tools.generic.ListToollt;/classgt;lt;/toolgt;
lt;/toolboxgt;
I haven't got a clue what's wrong here, anyone does?
What version of Spring / Velocity are you using? Did you see any logs from Velocity Tools - it looks to me like the toolbox didn't get initialised.
Spring 1.2.8
Velocity 1.4
I think the toolbox didnt initialize...
Loading an empty toolbox xml gives the same nullpointer...
You should see some logging from Velocity tools that will tell you about the exception it encountered: probably the resource doesn't exist (i.e. you put the toolbox xml in the wrong place). Try enabling logging on org.apache.velocity or org.apache.velocity.tools if you don't already.
.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
at org.apache.tomcat.util.net.MasterSlaveWorkerThread.run(MasterSlaveWorkerThread.java:112)
at java.lang.Thread.run(Thread.java:595)
I haven't got a clue what's wrong here...
Originally Posted by MielWhen i deploy my war, i see the following log statement:
I see no specific toolbox logging there, should i see that?
I would expect to see a message from the velocity toolbox factory saying why it had returned a null toolbox. Did you switch on logging on org.apache.velocity (I'm pretty sure that's where it should be coming out)?
I can't see anything obviously wrong with your configuration. Are you sure that the toolbox config file is actually deployed in the war?
David,
JBoss log4j config limited all org.apache logging to INFO and higher...
Turning that off results in an exponentially growing logfile (27mb just after starting jboss )...
However, the logfile shows nothing Toolbox specific... (except the 'Using VelocityToolboxView instead of...' line)
The toolbox is definately in the right place (in web-inf, named toolbox.xml)
Ok, did some further testing...
completely f*cking up the toolbox xml file, specifying another toolboxConfigLocation (one that doesn't exist), both had no effect whatsoever.
So it seems the toolbox config doesn't get loaded at all. Spring does notice that i specified a toolbox-location, since it replaced VelocityView with VelocityToolboxView, but nothing else happens..
Maybe i'm missing something fundamental here, but as far i reckon, the following steps are all that's needed to expose tools to my view templates:
* specify toolboxConfigLocation in ViewResolver
* place toolbox config file at that location...
Do i need to do anything else?
Took me a while, but here goes:
This fails:
Code:
lt;property name=quot;toolboxConfigLocationquot;gt;
lt;valuegt;
/WEB-INF/toolbox.xml
lt;/valuegt;
lt;/propertygt;
However, this works:
Code:
lt;property name=quot;toolboxConfigLocationquot; value=quot;/WEB-INF/toolbox.xmlquot;/gt;
Is it just me or is this weird...
Other param values can be specified through either a nested value element or a value attribute... The only exception is the darn toolbox config location!
Must be the whitespace I guess. Good to know it's not trimmed. |
|