You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by "McKenzie, Kevin" <km...@silverstream.com> on 2001/03/13 16:32:27 UTC

Debugging templates

I have been looking at Velocity for the last couple of days
and have got the forumdemo application running.

I am now trying to build and debug my first application.
I have an action class that obtains a collection of documents
represented by a Java object.  I put these in the context
with ctx.put( "listAll", myCollection.toArray() );

My template has the following code:

      #if ( $hasDocuments )
       #foreach ( $item in $listAll )
        <tr>
          <td bgcolor="#eeeeee" align="center">
            DOC:  $item.getName()
          </td>
        </tr>
       #end
      #else
       <tr>
         <td bgcolor="#eeeeee" colspan="4">
          <b>No documents found</b> Please try another query!
         </td>
       </tr>
      #end

My collection is not null, however, my output page only shows
the label Name: and no actual document names.

The velocity log doesn't help:
...
Tue Mar 13 10:18:40 EST 2001   [info]
     ** Property Override : runtime.log.warn.stacktrace = true
Tue Mar 13 10:18:40 EST 2001   [info]
     ** Property Override : runtime.log.info.stacktrace = true
Tue Mar 13 10:18:40 EST 2001   [info]
     ** Property Override : runtime.log.error.stacktrace = true
Tue Mar 13 10:18:40 EST 2001   [info]
     ** Property Override : counter.initial.value = 0
Tue Mar 13 10:18:40 EST 2001   [info]
     ** Property Override : resource.loader.1.resource.path = template
...
Tue Mar 13 10:18:42 EST 2001   [info] Attempting to find
  http://localhost/MSSQLportal/cm/template/doclist.vm with
  org.apache.velocity.runtime.resource.loader.AgResourceLoader

I searched the mail archives but could not find any relevant
information on debugging.

Can anyone point me in the right direction?

Thanks,
Kevin

Re: Debugging templates

Posted by "McKenzie, Kevin" <km...@silverstream.com>.
At 10:11 AM 3/13/2001 -0800, you wrote:
>TURN OFF HTML EMAIL!

Ok (apologies).

>on 3/13/01 9:41 AM, "McKenzie, Kevin" <km...@silverstream.com> wrote:
>
> > I'm not running Tomcat.  :-)
>
>Did you even look at the URL that I sent?

Yes.  However, I didn't try this as I had already got the demo running on
my server (SilverStream 3.7).

> > It is a Collection of EbiDocument objects, which extends
> > EbiDirectoryEntry:
> >
> > Method Summary
> > java.lang.String getID() Get the ID of the Directory Entry.
> > java.lang.String getKey() Get the key representing this entry in the
> > directory list.
> > java.lang.String getName() Get the name of the Directory Entry.
> > java.lang.String getURL(boolean encode) Get the URL of the Directory
> > Entry.
> > boolean isDirectory() Determine whether the entry is a directory.
> > void setName(java.lang.String name) Set the name of this entry to a new
> > value.
>
>So, then that should work.
>
> > I searched the mail archives but could not find any relevant
> > information on debugging.
> > Can anyone point me in the right direction?
>
>There isn't much to debug other than looking in the log file.
>
>There are also several variables you can add to your velocity.properties
>file...they are documented here:
>
>./src/java/org/apache/velocity/runtime/defaults/velocity.properties
>
>As well as on the website:
>
>http://jakarta.apache.org/velocity/developer-guide.html
>
>The documentation for Velocity is quite good. I suggest that you read it.

Thanks, I did read the Developer's Guide and the User's Guide and the
VTL Reference Guide.  I also took a look at the default velocity.properties
file and added overrides to my project's velocity.properties to force
Runtime.error(), info() and warn() messages to include the whole stack
trace.

> > I got my code working
>
>Uh. What was the problem?

It turns out that the ContentManager I was calling to get the Collection
of documents matching my query was not returning null when it found
no documents.  So my QueryCommand action was setting
"hasDocuments" to Boolean.TRUE but putting an empty Array in to
the VelocityContext.  Duh.

I hope I haven't come across as someone who posts before reading
and researching.  I like Velocity a lot, I read the documentation with
interest and look forward to working with such a well constructed
template engine.

-kevin



>-jon

Re: Debugging templates

Posted by Jon Stevens <jo...@latchkey.com>.
TURN OFF HTML EMAIL!

on 3/13/01 9:41 AM, "McKenzie, Kevin" <km...@silverstream.com> wrote:

> I'm not running Tomcat.  :-)

Did you even look at the URL that I sent?

> It is a Collection of EbiDocument objects, which extends
> EbiDirectoryEntry:
> 
> Method Summary 
> java.lang.String getID() Get the ID of the Directory Entry.
> java.lang.String getKey() Get the key representing this entry in the
> directory list.
> java.lang.String getName() Get the name of the Directory Entry.
> java.lang.String getURL(boolean encode) Get the URL of the Directory
> Entry.
> boolean isDirectory() Determine whether the entry is a directory.
> void setName(java.lang.String name) Set the name of this entry to a new
> value.

So, then that should work.

> I searched the mail archives but could not find any relevant
> information on debugging.
> Can anyone point me in the right direction?

There isn't much to debug other than looking in the log file.

There are also several variables you can add to your velocity.properties
file...they are documented here:

./src/java/org/apache/velocity/runtime/defaults/velocity.properties

As well as on the website:

http://jakarta.apache.org/velocity/developer-guide.html

The documentation for Velocity is quite good. I suggest that you read it.

> I got my code working

Uh. What was the problem?

-jon


Re: Debugging templates

Posted by "McKenzie, Kevin" <km...@silverstream.com>.
At 09:17 AM 3/13/2001 -0800, you wrote:


on 3/13/01 7:32 AM, "McKenzie, Kevin" <km...@silverstream.com>
wrote:

> I have been looking at Velocity for the last couple of days
> and have got the forumdemo application running.

That's good. All you have to do is download it and run Tomcat. :-)


I'm not running Tomcat.  :-)



...

why not:

#if ($listAll.size() > 0)

??????


Good suggestion.  I will do this.




...
What does your myCollection.toArray() object look like? Does it have a
getName() method?


It is a Collection of EbiDocument objects, which extends
EbiDirectoryEntry:

Method Summary 
java.lang.String getID() Get the ID of the Directory Entry.
java.lang.String getKey() Get the key representing this entry in the
directory list.
java.lang.String getName() Get the name of the Directory Entry.
java.lang.String getURL(boolean encode) Get the URL of the Directory
Entry.
boolean isDirectory() Determine whether the entry is a directory.
void setName(java.lang.String name) Set the name of this entry to a new
value.





I searched the mail archives but could not find any relevant 
information on debugging.
Can anyone point me in the right direction?



I got my code working, but am still interested in hearing about
debugging techniques using Velocity.

Thanks in advance,
Kevin




-jon

-- 
If you come from a Perl or PHP background, JSP is a way to take
your pain to new levels. --Anonymous
< http://jakarta.apache.org/velocity/ymtd/ymtd.html
<http://jakarta.apache.org/velocity/ymtd/ymtd.html> > 


Re: Debugging templates

Posted by Jon Stevens <jo...@latchkey.com>.
on 3/13/01 7:32 AM, "McKenzie, Kevin" <km...@silverstream.com> wrote:

> I have been looking at Velocity for the last couple of days
> and have got the forumdemo application running.

That's good. All you have to do is download it and run Tomcat. :-)

http://jakarta.apache.org/builds/jakarta-velocity/demo/

> I am now trying to build and debug my first application.
> I have an action class that obtains a collection of documents
> represented by a Java object.  I put these in the context
> with ctx.put( "listAll", myCollection.toArray() );
> 
> My template has the following code:
> 
> #if ( $hasDocuments )

why not:

#if ($listAll.size() > 0)

??????

> #foreach ( $item in $listAll )
> <tr>
> <td bgcolor="#eeeeee" align="center">
> DOC:  $item.getName()
> </td>
> </tr>
> #end
> #else
> <tr>
> <td bgcolor="#eeeeee" colspan="4">
> <b>No documents found</b> Please try another query!
> </td>
> </tr>
> #end
> 
> My collection is not null, however, my output page only shows
> the label Name: and no actual document names.

What does your myCollection.toArray() object look like? Does it have a
getName() method?

-jon

-- 
If you come from a Perl or PHP background, JSP is a way to take
your pain to new levels. --Anonymous
<http://jakarta.apache.org/velocity/ymtd/ymtd.html>