On 2/20/07, janbrito <[EMAIL PROTECTED]> wrote:

Hi, I'm trying to get Velocity working on a struts application. This is what
I've dono so far:

Have you looked at the "struts" example application that comes with
VelocityTools?  That might help you find problems in your setup.

1) Added to the project the velocity libraries (velocity-1.4.jar,
velocity-dep-1.4.jar and velocity-tools-1.3.jar)

I strongly recommend upgrading to velocity-dep-1.5-beta2.  It is quite
stable and contains numerous bug fixes and improvements.   Velocity
1.5 final should be released in just a week or so, and there have been
few changes since 1.5-beta2.

2) Added this to my web.xml file:

<servlet>
        <servlet-name>velocity</servlet-name>
        <servlet-class>
            org.apache.velocity.tools.view.servlet.VelocityViewServlet
        </servlet-class>
        <init-param>
            <param-name>org.apache.velocity.toolbox</param-name>
            <param-value>/WEB-INF/toolbox.xml</param-value>
        </init-param>
  </servlet>

  <servlet-mapping>
        <servlet-name>velocity</servlet-name>
        <url-pattern>*.vm</url-pattern>
  </servlet-mapping>

looks good

3) Created the toolbox.xml file in WEB-INF dir with this content:

<?xml version="1.0"?>
<toolbox>
  <tool>
     <key>link</key>
     <scope>request</scope>
     <class>
       org.apache.velocity.tools.struts.StrutsLinkTool
     </class>
  </tool>
  <tool>
     <key>msg</key>
     <scope>request</scope>
     <class>
       org.apache.velocity.tools.struts.MessageTool
     </class>
  </tool>
  <tool>
     <key>errors</key>
     <scope>request</scope>
     <class>
       org.apache.velocity.tools.struts.ErrorsTool
     </class>
  </tool>
  <tool>
     <key>form</key>
     <scope>request</scope>
     <class>
       org.apache.velocity.tools.struts.FormTool
     </class>
  </tool>
  <tool>
     <key>tiles</key>
     <scope>request</scope>
     <class>
       org.apache.velocity.tools.struts.TilesTool
     </class>
  </tool>
  <tool>
     <key>validator</key>
     <scope>request</scope>
     <class>
       org.apache.velocity.tools.struts.ValidatorTool
     </class>
  </tool>
</toolbox>

looks good.

4) Created an example index.vm file with only this code:

<html>
<head>
<title>$msg.get("label.portal.welcome")</title>
</head>
<body bgcolor="white">

</body>
</html>

looks fine, but you can simplify it a bit by changing

$msg.get("label.portal.welcome")   ->   $msg.label.portal.welcome

label.portal.welcome is defined on my ApplicationResource.properties struts
file.

When I access the index file I get the following error:

VelocityViewServlet : Error processing a template for path '/jsp/index.vm'

java.lang.NullPointerException
        at org.apache.velocity.io.VelocityWriter.write(VelocityWriter.java:319)
        at

i don't remember the exact trigger for this, but this is a bug which
has been fixed in Velocity 1.5-beta2.

<snip/>

So I pretty sure I've missed a step or two when setting Velocity up :)

i'm not sure.  do you have logging setup?

Also, I would like to know how do I replace velocity tags with database
values I retrieve on my action classes.

in your action, put those database values into the HttpServletRequest
attributes:

request.setAttribute("myDBValue", myDBValue);

then, in your template, just do:

$myDBValue


Thanks
--
View this message in context: 
http://www.nabble.com/Velocity-Struts-tf3263441.html#a9071152
Sent from the Velocity - User mailing list archive at Nabble.com.


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



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

Reply via email to