You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by Rafal Krzewski <Ra...@e-point.pl> on 2001/06/09 00:46:32 UTC

int valued expressions

Hello.

A friend of mine has encountered something that he believes to be a bug.
He asked me to translate the bug report to English for him, so here
goes...

Consider the following class

public class TableView
{
    // ...

    public int getInt()
    {
        return 1;
    }

    public String getString()
    {
        return "1";
    }
}

An instance of the above class is placed in the template context under
the key 'table'

Consider the following template:

##...
$link.set("testValue",$table.getInt()) (getInt)<br>
$link.set("testValue","$table.getInt()") ("getInt")<br>
$link.set("testValue",$table.getString()) (getString)<br>
##...

The actual output of the template is as follows

$link.set("testValue",$table.getInt()) (getInt)
/app/servlet/Turbine/view/BeanScreen/testValue/1/app/tabledemo
("getInt")
/app/servlet/Turbine/view/BeanScreen/testValue/1/app/tabledemo
(getString)

And the following error message appears in the log

2001 06 06 11:53:16 WARNING [velocity/tabledemo]  [warn]
org.apache.velocity.runtime.exception.ReferenceException: reference :
template = en_EN_HTML/screens/bean_screen.vt [line 16,column 1] :
$link.self().set("testValue",$table.getInt()) is not a valid reference.

Is this a bug of (mis)feature?

Rafal

PS. If you are wondering where those blurbs come from, it is the "new"
Turbine....

--
Rafal Krzewski
Senior Internet Developer
mailto:Rafal.Krzewski@e-point.pl
+48 22 8534830 http://e-point.pl

Re: int valued expressions

Posted by Rafal Krzewski <Ra...@e-point.pl>.
Leon Messerschmidt wrote:
> 
> Hi,
> 
> Can I take guess that the $link.set() takes a String as its second
> parameter?  I've had the same problem (in reverse).  My class took an int
> parameter and "1" gave the same error in the log.  I figured that automatic
> type conversion wasn't done for me so I just changed the object in the
> context....

Yeah, yeah the method takes a String... Please excuse the silly
question.
We need to add a few overloads (int, long, Object etc...)
 
> I'm not sure if type conversion is such a fantastic idea.  It will influence
> all kinds of stuff like arithmetic in #set and so on.  Besides it can easily
> be fixed by just overloading a couple of methods.

-1 to automatic type conversions done in Vel. Much complexit, little
benefit (IMO).


Sorry for a false alert...
Rafal

--
Rafal Krzewski
Senior Internet Developer
mailto:Rafal.Krzewski@e-point.pl
+48 22 8534830 http://e-point.pl

Re: int valued expressions

Posted by Leon Messerschmidt <le...@opticode.co.za>.
Hi,

Can I take guess that the $link.set() takes a String as its second
parameter?  I've had the same problem (in reverse).  My class took an int
parameter and "1" gave the same error in the log.  I figured that automatic
type conversion wasn't done for me so I just changed the object in the
context....

I'm not sure if type conversion is such a fantastic idea.  It will influence
all kinds of stuff like arithmetic in #set and so on.  Besides it can easily
be fixed by just overloading a couple of methods.

~ Leon

----- Original Message -----
From: "Geir Magnusson Jr." <ge...@optonline.net>
To: <ve...@jakarta.apache.org>
Sent: Saturday, June 09, 2001 4:50 AM
Subject: Re: int valued expressions


> Rafal Krzewski wrote:
> >
> > Hello.
> >
> > A friend of mine has encountered something that he believes to be a bug.
> > He asked me to translate the bug report to English for him, so here
> > goes...
> >
> > Consider the following class
> >
> > public class TableView
> > {
> >     // ...
> >
> >     public int getInt()
> >     {
> >         return 1;
> >     }
> >
> >     public String getString()
> >     {
> >         return "1";
> >     }
> > }
> >
> > An instance of the above class is placed in the template context under
> > the key 'table'
> >
> > Consider the following template:
> >
> > ##...
> > $link.set("testValue",$table.getInt()) (getInt)<br>
> > $link.set("testValue","$table.getInt()") ("getInt")<br>
> > $link.set("testValue",$table.getString()) (getString)<br>
> > ##...
> >
> > The actual output of the template is as follows
> >
> > $link.set("testValue",$table.getInt()) (getInt)
> > /app/servlet/Turbine/view/BeanScreen/testValue/1/app/tabledemo
> > ("getInt")
> > /app/servlet/Turbine/view/BeanScreen/testValue/1/app/tabledemo
> > (getString)
> >
> > And the following error message appears in the log
> >
> > 2001 06 06 11:53:16 WARNING [velocity/tabledemo]  [warn]
> > org.apache.velocity.runtime.exception.ReferenceException: reference :
> > template = en_EN_HTML/screens/bean_screen.vt [line 16,column 1] :
> > $link.self().set("testValue",$table.getInt()) is not a valid reference.
> >
> > Is this a bug of (mis)feature?
>
> Hm.  It can't find, from the first use,  a method like
>
> set( Object, int )
>
> (or something like it - maybe set( String, int ) - I can't be sure...
>
> The second and third are ok because you have a
>
> set( Object, Object)
>
> (or set( String, String) ... )
>
> Also, the self() bit is a bit wierd
>
> What is the class behind the $link reference?
>
> > Rafal
> >
> > PS. If you are wondering where those blurbs come from, it is the "new"
> > Turbine....
>
> Version 2.1 ? :)
>
> (I know what you mean - I will try and find it....)
>
> geir
>
> --
> Geir Magnusson Jr.                           geirm@optonline.net
> System and Software Consulting
> Developing for the web?  See http://jakarta.apache.org/velocity/
> You have a genius for suggesting things I've come a cropper with!


Re: int valued expressions

Posted by "Geir Magnusson Jr." <ge...@optonline.net>.
Rafal Krzewski wrote:
> 
> Hello.
> 
> A friend of mine has encountered something that he believes to be a bug.
> He asked me to translate the bug report to English for him, so here
> goes...
> 
> Consider the following class
> 
> public class TableView
> {
>     // ...
> 
>     public int getInt()
>     {
>         return 1;
>     }
> 
>     public String getString()
>     {
>         return "1";
>     }
> }
> 
> An instance of the above class is placed in the template context under
> the key 'table'
> 
> Consider the following template:
> 
> ##...
> $link.set("testValue",$table.getInt()) (getInt)<br>
> $link.set("testValue","$table.getInt()") ("getInt")<br>
> $link.set("testValue",$table.getString()) (getString)<br>
> ##...
> 
> The actual output of the template is as follows
> 
> $link.set("testValue",$table.getInt()) (getInt)
> /app/servlet/Turbine/view/BeanScreen/testValue/1/app/tabledemo
> ("getInt")
> /app/servlet/Turbine/view/BeanScreen/testValue/1/app/tabledemo
> (getString)
> 
> And the following error message appears in the log
> 
> 2001 06 06 11:53:16 WARNING [velocity/tabledemo]  [warn]
> org.apache.velocity.runtime.exception.ReferenceException: reference :
> template = en_EN_HTML/screens/bean_screen.vt [line 16,column 1] :
> $link.self().set("testValue",$table.getInt()) is not a valid reference.
> 
> Is this a bug of (mis)feature?

Hm.  It can't find, from the first use,  a method like 

set( Object, int )

(or something like it - maybe set( String, int ) - I can't be sure...

The second and third are ok because you have a 

set( Object, Object)

(or set( String, String) ... )

Also, the self() bit is a bit wierd

What is the class behind the $link reference?

> Rafal
> 
> PS. If you are wondering where those blurbs come from, it is the "new"
> Turbine....

Version 2.1 ? :)

(I know what you mean - I will try and find it....)

geir

-- 
Geir Magnusson Jr.                           geirm@optonline.net
System and Software Consulting
Developing for the web?  See http://jakarta.apache.org/velocity/
You have a genius for suggesting things I've come a cropper with!