You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@velocity.apache.org by Terry Steichen <te...@net-frame.com> on 2001/10/12 05:38:10 UTC

VTL Logic Problem

All,

I'm having trouble making some simple-looking VTL branching logic work.  It
looks like this:

1    #foreach($item in $items)
2        #set ($test = $item.Folder_code)
3        <td>$test</td>
4        #if($test == 0)
5            <td>file</td>
6        #else
7        <td>folder</td>
8        #end
9    #end

The value of $test that is printed is just fine (line 3 above) - but the branching logic
(lines 4 through 8) doesn't work at all.

Now if I change the #set line to directly assign any number to $test (line 2)
equent branching logic works just fine.  The problem seems to be in
assigning $test the value of $item.Folder_code (line 2), which happens to be a byte.

I went through the docs and the archives trying to figure this out.  Could
any of you give me an idea on what the heck I'm doing wrong?

Regards,

Terry Steichen


Re: VTL Logic Problem

Posted by Bojan Smojver <bo...@binarix.com>.
Terry Steichen wrote:
> 
> All,
> 
> I'm having trouble making some simple-looking VTL branching logic work.  It
> looks like this:
> 
> 1    #foreach($item in $items)
> 2        #set ($test = $item.Folder_code)
> 3        <td>$test</td>
> 4        #if($test == 0)
> 5            <td>file</td>
> 6        #else
> 7        <td>folder</td>
> 8        #end
> 9    #end
> 
> The value of $test that is printed is just fine (line 3 above) - but the branching logic
> (lines 4 through 8) doesn't work at all.
> 
> Now if I change the #set line to directly assign any number to $test (line 2)
> equent branching logic works just fine.  The problem seems to be in
> assigning $test the value of $item.Folder_code (line 2), which happens to be a byte.
> 
> I went through the docs and the archives trying to figure this out.  Could
> any of you give me an idea on what the heck I'm doing wrong?

This is more of a velocity-user list question, anyway...

Doesn't Velocity deal with Integer numbers only? Maybe you should return
Integer into $item.Folder_code?

Bojan

PS. This stuff can be found in User Guide.

Re: VTL Logic Problem

Posted by "Henning P. Schmiedehausen" <ma...@hometree.net>.
"Terry Steichen" <te...@net-frame.com> writes:

>option, as it is part of a core data class.  The easiest fix (once I
>realized the cause of the problem) was to make the following changes:
>    -in the Java module, add this line: context.put("byte", new
>Byte((byte)0));
>    -in the template, change previous line to this:
>#if($byte.toString($item.Folder_code) == "0")

I wouldn't call _that_ easy... (Hey, the week of "we don't talk about
numbers and comparisations" pause _is_ over... ;-) )

	Regards
		Henning
-- 
Dipl.-Inf. (Univ.) Henning P. Schmiedehausen       -- Geschaeftsfuehrer
INTERMETA - Gesellschaft fuer Mehrwertdienste mbH     hps@intermeta.de

Am Schwabachgrund 22  Fon.: 09131 / 50654-0   info@intermeta.de
D-91054 Buckenhof     Fax.: 09131 / 50654-20   

Re: VTL Logic Problem

Posted by "Geir Magnusson Jr." <ge...@optonline.net>.
On 10/12/01 10:20 AM, "Terry Steichen" <te...@net-frame.com> wrote:

> All,
> 
> Many thanks.  Changing $item.Folder_code from a byte to an int wasn't a good
> option, as it is part of a core data class.  The easiest fix (once I
> realized the cause of the problem) was to make the following changes:
>   -in the Java module, add this line: context.put("byte", new
> Byte((byte)0));
>   -in the template, change previous line to this:
> #if($byte.toString($item.Folder_code) == "0")

Sure. 

> 
> BTW, I'm *very* impressed with Velocity.  I'm converting an entire
> Enhydra-based application to it as we speak (well over 100 'pages').  Since
> I'm still in a 'beginner's mind" mode (read, Velocity newbie), here are a
> couple of observations so far in terms of formal user/developer
> documentation suggestions:

We would love to have a write-up of your experience in the conversion
process (to post on the site here...)

> 
> 1. make it more clear that string varbs are concatenated without '+' between
> terms and *must* be enclosed in quotes.

Yep.

> 2. explain how $formatter works

Yep

> 3. explain how to make comparisons with non-integer values

Yep
 
> I'm learning that Velocity is *incredibly* powerful and flexible, but I also
> find I have to dig around a lot to find how to use some of these
> capabilities.  I'd be glad to help someone insert these suggested wording
> additions (and others I find) into the docs if desired.

I'll throw some up today, and if you could review to ensure that the wording
is right for a newbie, that would be great.
 
> Best regards,
> 
> Terry
> 
> ----- Original Message -----
> From: "Geir Magnusson Jr." <ge...@optonline.net>
> To: <ve...@jakarta.apache.org>
> Sent: Thursday, October 11, 2001 11:53 PM
> Subject: Re: VTL Logic Problem
> 
> 
>> On 10/11/01 11:38 PM, "Terry Steichen" <te...@net-frame.com> wrote:
>> 
>>> All,
>>> 
>>> I'm having trouble making some simple-looking VTL branching logic work.
> It
>>> looks like this:
>>> 
>>> 1    #foreach($item in $items)
>>> 2        #set ($test = $item.Folder_code)
>>> 3        <td>$test</td>
>>> 4        #if($test == 0)
>>> 5            <td>file</td>
>>> 6        #else
>>> 7        <td>folder</td>
>>> 8        #end
>>> 9    #end
>>> 
>>> The value of $test that is printed is just fine (line 3 above) - but the
>>> branching logic
>>> (lines 4 through 8) doesn't work at all.
>>> 
>>> Now if I change the #set line to directly assign any number to $test
> (line 2)
>>> equent branching logic works just fine.  The problem seems to be in
>>> assigning $test the value of $item.Folder_code (line 2), which happens
> to be a
>>> byte.
>> 
>> A byte?  No, that won't work.  Integer comparisons only.
>> 
>>> 
>>> I went through the docs and the archives trying to figure this out.
> Could
>>> any of you give me an idea on what the heck I'm doing wrong?
>>> 
>> 
>> Make folder code an integer, or add a little tool :
>> 
>> #if ($tool.eq( $item.Folder_code, 0 ) )
>> 
>> geir
>> 
>> --
>> Geir Magnusson Jr.     geirm@optonline.net
>> System and Software Consulting
>> "They that can give up essential liberty to obtain a little temporary
> safety
>> deserve neither liberty nor safety." - Benjamin Franklin
>> 
>> 
>> 
> 

-- 
Geir Magnusson Jr.                       geirm@optonline.net
System and Software Consulting
You're going to end up getting pissed at your software
anyway, so you might as well not pay for it. Try Open Source.



Re: VTL Logic Problem

Posted by Terry Steichen <te...@net-frame.com>.
All,

Many thanks.  Changing $item.Folder_code from a byte to an int wasn't a good
option, as it is part of a core data class.  The easiest fix (once I
realized the cause of the problem) was to make the following changes:
    -in the Java module, add this line: context.put("byte", new
Byte((byte)0));
    -in the template, change previous line to this:
#if($byte.toString($item.Folder_code) == "0")

BTW, I'm *very* impressed with Velocity.  I'm converting an entire
Enhydra-based application to it as we speak (well over 100 'pages').  Since
I'm still in a 'beginner's mind" mode (read, Velocity newbie), here are a
couple of observations so far in terms of formal user/developer
documentation suggestions:

1. make it more clear that string varbs are concatenated without '+' between
terms and *must* be enclosed in quotes.
2. explain how $formatter works
3. explain how to make comparisons with non-integer values

I'm learning that Velocity is *incredibly* powerful and flexible, but I also
find I have to dig around a lot to find how to use some of these
capabilities.  I'd be glad to help someone insert these suggested wording
additions (and others I find) into the docs if desired.

Best regards,

Terry

----- Original Message -----
From: "Geir Magnusson Jr." <ge...@optonline.net>
To: <ve...@jakarta.apache.org>
Sent: Thursday, October 11, 2001 11:53 PM
Subject: Re: VTL Logic Problem


> On 10/11/01 11:38 PM, "Terry Steichen" <te...@net-frame.com> wrote:
>
> > All,
> >
> > I'm having trouble making some simple-looking VTL branching logic work.
It
> > looks like this:
> >
> > 1    #foreach($item in $items)
> > 2        #set ($test = $item.Folder_code)
> > 3        <td>$test</td>
> > 4        #if($test == 0)
> > 5            <td>file</td>
> > 6        #else
> > 7        <td>folder</td>
> > 8        #end
> > 9    #end
> >
> > The value of $test that is printed is just fine (line 3 above) - but the
> > branching logic
> > (lines 4 through 8) doesn't work at all.
> >
> > Now if I change the #set line to directly assign any number to $test
(line 2)
> > equent branching logic works just fine.  The problem seems to be in
> > assigning $test the value of $item.Folder_code (line 2), which happens
to be a
> > byte.
>
> A byte?  No, that won't work.  Integer comparisons only.
>
> >
> > I went through the docs and the archives trying to figure this out.
Could
> > any of you give me an idea on what the heck I'm doing wrong?
> >
>
> Make folder code an integer, or add a little tool :
>
> #if ($tool.eq( $item.Folder_code, 0 ) )
>
> geir
>
> --
> Geir Magnusson Jr.     geirm@optonline.net
> System and Software Consulting
> "They that can give up essential liberty to obtain a little temporary
safety
> deserve neither liberty nor safety." - Benjamin Franklin
>
>
>


Re: VTL Logic Problem

Posted by "Geir Magnusson Jr." <ge...@optonline.net>.
On 10/11/01 11:38 PM, "Terry Steichen" <te...@net-frame.com> wrote:

> All,
> 
> I'm having trouble making some simple-looking VTL branching logic work.  It
> looks like this:
> 
> 1    #foreach($item in $items)
> 2        #set ($test = $item.Folder_code)
> 3        <td>$test</td>
> 4        #if($test == 0)
> 5            <td>file</td>
> 6        #else
> 7        <td>folder</td>
> 8        #end
> 9    #end
> 
> The value of $test that is printed is just fine (line 3 above) - but the
> branching logic
> (lines 4 through 8) doesn't work at all.
> 
> Now if I change the #set line to directly assign any number to $test (line 2)
> equent branching logic works just fine.  The problem seems to be in
> assigning $test the value of $item.Folder_code (line 2), which happens to be a
> byte.

A byte?  No, that won't work.  Integer comparisons only.

> 
> I went through the docs and the archives trying to figure this out.  Could
> any of you give me an idea on what the heck I'm doing wrong?
> 

Make folder code an integer, or add a little tool :

#if ($tool.eq( $item.Folder_code, 0 ) )

geir

-- 
Geir Magnusson Jr.     geirm@optonline.net
System and Software Consulting
"They that can give up essential liberty to obtain a little temporary safety
deserve neither liberty nor safety." - Benjamin Franklin