You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by specialist33 <sp...@grexengine.com> on 2004/10/10 17:02:48 UTC

Velocity "is not a valid reference" error...help?

I'm getting an incomprehensible "is not a valid ref" error. I've spent 
some hours trying to solve it, but I'm not being helped by the fact that 
I cannot seem to find a way of getting velocity to tell me what WOULD be 
a valid reference or WHY this is not a valid ref.

These would seem to be obvious components of that error message, yet are 
absent and despite having re-read the developer and user guides several 
times I can't see a way at getting at that info (surely there is some way?)

(Basically, I expected there to be something that would do the same as 
javap, except from Velocity's perspective, so that you could see what it 
thought it could see)

Anyway, the problem is this.

1. I have an interface, iAccount
2. Which has several methods, including: public String getLogin();
3. I have a class that implements that, BaseAccount
4. I insert a valid BaseAccount instance in the velocity context 
(context.put( "account", instance );)
5. I have a template with:

<html>
<body>
<h1>Testing cookies.</h1>
Checking to see if a cookie was sent that was interpreted as an account
<p>
Value of account in template context is:
$account.class
$account
${account.class.name}
<p>
Value of "account.getLogin()" in template context is $account.getLogin()
<p>
Value of "account.getLogin" in template context is $account.getLogin
<p>
Value of "account.Login" in template context is $account.Login
</body>
</html>

i.e. there are 6 uses of the account ref.

6. When I run the template, the first 3 refs all report that $account is 
a BaseAccount instance (the second does this because it has a default 
toString(), which as you know outputs the classname by default)

7. BUT the other three references are passed through unchanged, and 
trigger log messages about "is not a valid reference".

8. BaseAccount is a "public class" and iAccount is a "public interface".

9. javap output on BaseAccount reveals:

Compiled from "BaseAccount.java"
public class [snip package].BaseAccount extends java.lang.Object 
implements [snip package].iAccount{
     protected java.lang.String login;
     protected java.lang.String password;
     public [snip package].BaseAccount();
     public java.lang.String getLogin();
     [snip other methods]
}

AFAICS I've done everything correctly. OBviously, I haven't. But I can't 
for the life of me work out what I've done wrong. Sob.

Any suggestions?

PS: this is velocity 1.4 running on java 1.4.2_05 on linux

---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org


Re: Velocity "is not a valid reference" error...help?

Posted by Shinobu Kawai <sh...@gmail.com>.
Hi specialist33,

> First two items are:
> 
> public java.util.Collection [package].BaseAccount.groups()
> public java.lang.String [package].BaseAccount.getLogin()
Weird...

> So. It seems velocity CAN see the methods, it's just being evil and
> refusing to call them :(.
Yes, what's confusing me more, is that it's working in my environment.

> What now? This was a standard 1.4 download direct from the apache site,
> with no recompilation or etc, and works fine otherwise - but it seems
> broken???
Okay, here's the class Velocity uses to look up methods.
org.apache.velocity.util.introspection.ClassMap

Inside of your java code, try this:

ClassMap map = new ClassMap(BaseAccount.class)
// replace log with any log mechanism you're using, or System.out.println
log("BaseAccount#getLogin() : " + map.findMethod("getLogin", new Object[0]));

If this turns out null, there's something wrong with your class/method
modifiers.  If it shows the method, we might have a bug in Velocity. 
(Or some environmental problem.)

> PS thanks for the foreach idea...thats the kind of debugging I was
> trying to think of :).
No sweat.

Best regards,
-- Shinobu Kawai

-- 
Shinobu Kawai <sh...@gmail.com>

---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org


Re: Velocity "is not a valid reference" error...help?

Posted by specialist33 <sp...@grexengine.com>.
Shinobu Kawai wrote:
> Hi specialist33,
> 
> 
>>i.e. they passed through unchanged, with the classic error message :((.
>>
> 
> You know what?  I haven't a clue...
> $accounts.class worked, right?  Let's try this:
> 
> #foreach($method in $account.class.methods)
> $method
> #end
> 
> See if it shows a "public java.lang.String ...BaseAcount.getLogin()".

First two items are:

public java.util.Collection [package].BaseAccount.groups()
public java.lang.String [package].BaseAccount.getLogin()

where [package] == the package which the iAccount and BaseAccount are 
both in.

The rest of the methods are also there, as well as the Object methods 
(as you'd expect, yes?)

So. It seems velocity CAN see the methods, it's just being evil and 
refusing to call them :(.

What now? This was a standard 1.4 download direct from the apache site, 
with no recompilation or etc, and works fine otherwise - but it seems 
broken???

PS thanks for the foreach idea...thats the kind of debugging I was 
trying to think of :).

---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org


Re: Velocity "is not a valid reference" error...help?

Posted by Shinobu Kawai <sh...@gmail.com>.
Hi specialist33,

> i.e. they passed through unchanged, with the classic error message :((.
> 
> org.apache.velocity.runtime.exception.ReferenceException: reference :
> template = testcookie [line 5,column 1] : ${account.getLogin()} is not a
> valid reference. [org.apache.velocity.runtime.log.SimpleLog4JLogSystem]
> 
> ...etc
You know what?  I haven't a clue...
$accounts.class worked, right?  Let's try this:

#foreach($method in $account.class.methods)
$method
#end

See if it shows a "public java.lang.String ...BaseAcount.getLogin()".

Best regards,
-- Shinobu Kawai

-- 
Shinobu Kawai <sh...@gmail.com>

---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org


Re: Velocity "is not a valid reference" error...help?

Posted by specialist33 <sp...@grexengine.com>.
Shinobu Kawai wrote:
>>7. BUT the other three references are passed through unchanged, and
>>trigger log messages about "is not a valid reference".
> 
> 
> I don't know what's going on, but the fifth one is not a valid
> reference, even if it were working.  I tried something similar, but

Yes, I was getting desperate, and started trying *anything* that might 
work ;).

> they all worked fine.  Really is strange.  What do the following
> output?
> $account.login
> ${account.getLogin()}
> ${account.Login}
> ${account.login}
> 

$account.login
${account.getLogin()}
${account.Login}
${account.login}

i.e. they passed through unchanged, with the classic error message :((.

org.apache.velocity.runtime.exception.ReferenceException: reference : 
template = testcookie [line 5,column 1] : ${account.getLogin()} is not a 
valid reference. [org.apache.velocity.runtime.log.SimpleLog4JLogSystem]

...etc

---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org


Re: Velocity "is not a valid reference" error...help?

Posted by Shinobu Kawai <sh...@gmail.com>.
Hi, um... specialist33,

> 1. I have an interface, iAccount
> 2. Which has several methods, including: public String getLogin();
> 3. I have a class that implements that, BaseAccount
> 4. I insert a valid BaseAccount instance in the velocity context
> (context.put( "account", instance );)
> 5. I have a template with:

## snip

> Value of "account.getLogin()" in template context is $account.getLogin()
> <p>
> Value of "account.getLogin" in template context is $account.getLogin
> <p>
> Value of "account.Login" in template context is $account.Login
> </body>
> </html>

## snip

> 7. BUT the other three references are passed through unchanged, and
> trigger log messages about "is not a valid reference".

I don't know what's going on, but the fifth one is not a valid
reference, even if it were working.  I tried something similar, but
they all worked fine.  Really is strange.  What do the following
output?
$account.login
${account.getLogin()}
${account.Login}
${account.login}

Best regards,
-- Shinobu Kawai

-- 
Shinobu Kawai <sh...@gmail.com>

---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org


Re: Struts Javascript Validators

Posted by Eric Fixler <fi...@fixler.com>.
Hi Shinobu.

>>
> Could it have something to do with this?
> - Client-side javascript validation incorrect for new commons-validator
>   http://issues.apache.org/bugzilla/show_bug.cgi?id=31971

I read the bugzilla report and this is exactly the problem.

I looked at the patch, and it looks simple enough so I'll try it and 
post back.

I'm not familiar enough with writing Java-style objects in javascript, 
(i.e. things that use the 'this' keyword), but it looks to me like it 
would need more...but hopefully I'm wrong.

Thanks!
eric



---------------------------------------------------------------------
Eric Fixler
fix@fixler.com


---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org


Re: Struts Javascript Validators

Posted by Shinobu Kawai <sh...@gmail.com>.
Hi Eric,

> Hi all.  I'm wondering if anyone is successfully using Struts client 
> side validators in conjunction with ValidatorTool.
> 
> I believe that I have configured everything properly, and I get the 
> javascript in the vm output.  But it looks to me like there is a 
> javascript error, specifically, that there's something missing from the 
> dynamic section of the javascript, which is, I think, generated by the 
> tool.
> 
> To be specific:

## snip

> I would expect the formName_object to be here, but it's not.  Instead, 
> just a method called 'required', which refers to a 'this'.  The way I'm 
> looking at this, there's no object context there to be referred to by 
> this.
> 
> Anyway, that's the result of my investigation.  I'd really appreciate 
> some confirmation that this stuff is working out there in the real 
> world, plus any pointers to make it work.
Could it have something to do with this?
- Client-side javascript validation incorrect for new commons-validator
  http://issues.apache.org/bugzilla/show_bug.cgi?id=31971

Best regards,
-- Shinobu Kawai

--
Shinobu Kawai <sh...@gmail.com>


---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org


Struts Javascript Validators

Posted by Eric Fixler <fi...@fixler.com>.
Hi all.  I'm wondering if anyone is successfully using Struts client 
side validators in conjunction with ValidatorTool.

I believe that I have configured everything properly, and I get the 
javascript in the vm output.  But it looks to me like there is a 
javascript error, specifically, that there's something missing from the 
dynamic section of the javascript, which is, I think, generated by the 
tool.

To be specific:

- Here's a snippet from the required field validator, which is part of 
the static section and comes straight from Struts

function validateRequired(form) {
...
  oRequired = eval('new ' + formName.value + '_required()');
...
}

AFAICT, it's attempting to instantiate an object that will be used to 
figure out which field are required.  For a form called 'formName' 
there'd need to be a method called 'formName_required'.  There's no 
such method.  My log confirms this:

(event handler):Value undefined (result of expression 
simpleSearchForm_required) is not an object. Cannot be used with new.

- Here's the code of section of the dynamic javascript portion of the 
validator, which, I think, is generated by the ValidatorTool

      var bCancel = false;

     function validateSimpleSearchForm(form) {
         if (bCancel)
       return true;
         else
        return validateRequired(form);
    }

     function required () {
      this.aa = new Array("keyword", "null is required.", new Function 
("varName", " return this[varName];"));
     }


I would expect the formName_object to be here, but it's not.  Instead, 
just a method called 'required', which refers to a 'this'.  The way I'm 
looking at this, there's no object context there to be referred to by 
this.

Anyway, that's the result of my investigation.  I'd really appreciate 
some confirmation that this stuff is working out there in the real 
world, plus any pointers to make it work.

thanks!
eric
---------------------------------------------------------------------
Eric Fixler
fix@fixler.com


---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org


Re: Velocity "is not a valid reference" error...help?

Posted by Shinobu Kawai <sh...@gmail.com>.
Hi Nathan,

> > well, i'm pretty sure that schmoo like "$" and "$45" is not valid VTL and thus
> > not recognized as a reference by velocity and thus shouldn't generate a
> > warning.  and really, how often do you have a $ followed by anything else and
> > not have it be a reference?
> Let's see... (10 seconds of thinking)  None yet!  Hurray!
I just thought of one:  When you are using Velocity for code generation!
But then again, in those cases, the template designers are most likely
to be the programmers, so I'll just go ahead and say, "Shut up and use
${dollar}!"  ;)

Best regards,
-- Shinobu Kawai

-- 
Shinobu Kawai <sh...@gmail.com>

---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org


Re: Velocity "is not a valid reference" error...help?

Posted by Shinobu Kawai <sh...@gmail.com>.
Hi Nathan,

> well, i'm pretty sure that schmoo like "$" and "$45" is not valid VTL and thus
> not recognized as a reference by velocity and thus shouldn't generate a
> warning.  and really, how often do you have a $ followed by anything else and
> not have it be a reference?
Let's see... (10 seconds of thinking)  None yet!  Hurray!

>  also, i vaguely remember there being some
> configuration property to turn these warnings off, but i haven't the time
> right now to confirm that.
Found it:
    http://jakarta.apache.org/velocity/developer-guide.html#Velocity%20Configuration%20Keys%20and%20Values

runtime.log.invalid.references = true
Property to turn off the log output when a reference isn't valid. Good
thing to turn of in production, but very valuable for debugging.


> do understand though, that what the warning message is saying is not that
> $account.Login is invalid reference syntax.  it's pretty much just saying that
> the reference resolve to anything.  possible causes for that could be a
> syntactically valid reference with a legitimately null value (like our dear
> $account.Login) or a mistyped reference that is still valid syntactically
> (something like $acount or $account.nosuchmethod).  now, the two things that
> have much room for improvement here is the case of "$account.nosuchmethod".
> here it could be useful for Velocity to affirm that $account is not null, but
> it can't find a method on the object to match "nosuchmethod".  this could then
> be distinguished from situations like $account.Login where both the $account
> object is valid and a method matching "Login" was found, but the method
> returned a null value.
I guess an extra message for a legitimate null will do.  Checking if a
property/method was non-existing seems a bit complicated to me. 
Besides, those are the times when programmers are likely to say,
"What's going on here?".

Best regards,
-- Shinobu Kawai

-- 
Shinobu Kawai <sh...@gmail.com>

---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org


Re: Velocity "is not a valid reference" error...help?

Posted by Nathan Bubna <na...@esha.com>.
Shinobu Kawai said:
> > >  > problem is or else your getLogin() method is returning null.  can you
> > > assure
> > >
> > > ! This possibility entirely passed me by (its probably in the docs and I
> > > just didn't notice it, but it's very counter-intuitive),
> >
> > :)
> You guys sure got me on this one.  At least I learned a lot about
> Velocity's internal behaviour.  ;)
>
>
> > but there can be something wrong with displaying unrendered references in
a
> > template language.  thus the warning message.
> OTOH, every schmoo that looks like a reference causes a warning
> message.  Too bad Velocity can't decide whether it was meant to be or
> not.

yeah, it's not psychic. :)

> (And I don't want to go around telling all the template
> designers, use "${dollar}" instead of "$".  Although it would make
> life for the programmers a lot easier.  ;))

well, i'm pretty sure that schmoo like "$" and "$45" is not valid VTL and thus
not recognized as a reference by velocity and thus shouldn't generate a
warning.  and really, how often do you have a $ followed by anything else and
not have it be a reference?  also, i vaguely remember there being some
configuration property to turn these warnings off, but i haven't the time
right now to confirm that.

> > > I'm guessing an even better approach would be two separate messages, one
> > > for the "couldn't find a method" and another for "found a method but it
> > > returned null", and in both cases it ought to say what the method name
> > > it found (or tried to find) was. That would shortcut the debugging
> > > process considerably, and probably reduce the number of people in my
> > > situation who even needed to come to the list to ask for help :).
> >
> > yeah, that sounds like a worthy enhancement request.  i'd recommend filing
a
> > bug report on it so it doesn't get forgotten.  and, of course, if you can
come
> > up with a patch to go with it, that would be cool too.  i can't say
whether
> > it'll ever be applied, but i think this is a good idea.
> I'll vote on that one.  :)

do understand though, that what the warning message is saying is not that
$account.Login is invalid reference syntax.  it's pretty much just saying that
the reference resolve to anything.  possible causes for that could be a
syntactically valid reference with a legitimately null value (like our dear
$account.Login) or a mistyped reference that is still valid syntactically
(something like $acount or $account.nosuchmethod).  now, the two things that
have much room for improvement here is the case of "$account.nosuchmethod".
here it could be useful for Velocity to affirm that $account is not null, but
it can't find a method on the object to match "nosuchmethod".  this could then
be distinguished from situations like $account.Login where both the $account
object is valid and a method matching "Login" was found, but the method
returned a null value.

Nathan Bubna
nathan@esha.com


---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org


Re: Velocity "is not a valid reference" error...help?

Posted by Shinobu Kawai <sh...@gmail.com>.
Hi specialist33 & Nathan,

> >  > problem is or else your getLogin() method is returning null.  can you
> > assure
> >
> > ! This possibility entirely passed me by (its probably in the docs and I
> > just didn't notice it, but it's very counter-intuitive),
> 
> :)
You guys sure got me on this one.  At least I learned a lot about
Velocity's internal behaviour.  ;)


> but there can be something wrong with displaying unrendered references in a
> template language.  thus the warning message.
OTOH, every schmoo that looks like a reference causes a warning
message.  Too bad Velocity can't decide whether it was meant to be or
not.  (And I don't want to go around telling all the template
designers, use "${dollar}" instead of "$".  Although it would make
life for the programmers a lot easier.  ;))


> > I'm guessing an even better approach would be two separate messages, one
> > for the "couldn't find a method" and another for "found a method but it
> > returned null", and in both cases it ought to say what the method name
> > it found (or tried to find) was. That would shortcut the debugging
> > process considerably, and probably reduce the number of people in my
> > situation who even needed to come to the list to ask for help :).
> 
> yeah, that sounds like a worthy enhancement request.  i'd recommend filing a
> bug report on it so it doesn't get forgotten.  and, of course, if you can come
> up with a patch to go with it, that would be cool too.  i can't say whether
> it'll ever be applied, but i think this is a good idea.
I'll vote on that one.  :)

Best regards,
-- Shinobu Kawai

-- 
Shinobu Kawai <sh...@gmail.com>

---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org


Re: Velocity "is not a valid reference" error...help?

Posted by Nathan Bubna <na...@esha.com>.
specialist33 said:
> Nathan Bubna wrote:
> > specialist33 said:
> >
> >>I'm getting an incomprehensible "is not a valid ref" error. I've spent
> >>some hours trying to solve it, but I'm not being helped by the fact that
> >>I cannot seem to find a way of getting velocity to tell me what WOULD be
> >>a valid reference or WHY this is not a valid ref.
> >>
> >>summary == [it's a public method in a public class,
> >>and i'm doing the VTL syntax properly,
> >>but still getting error messages.  help!]
> >
> > ...
> >
> > ok, i agree.  you've got the public, public, public thing down, and you're
> > getting most of your references right, so i either don't have a clue what
the
>  > problem is or else your getLogin() method is returning null.  can you
> assure
>  > us that the latter is not the case?
>
> It was sometimes returning null, so I made it forced return something
> (in this case the string "unquoted3" (quotes only there to illustrate,
> as the name suggests the value had no quotes ;)). That produced the
> following log statements:
>
> [INFO]-I just put currentAccount = [package].BaseAccount@1cac6db into
> the context with getLogin = unquoted3
>
> [INFO]-ResourceManager : found testcookie with loader
> org.apache.velocity.runtime.resource.loader.FileResourceLoader
>
> [WARN]-org.apache.velocity.runtime.exception.ReferenceException:
> reference : template = testcookie [line 9,column 52] : $account.getLogin
> is not a valid reference.

$account.getLogin is not a valid reference. :)  but $account.Login,
$account.login, and $account.getLogin() are now, right?

> (note that "testcookie" is the literal name of the template file being
> used here).
>
>  > problem is or else your getLogin() method is returning null.  can you
> assure
>
> ! This possibility entirely passed me by (its probably in the docs and I
> just didn't notice it, but it's very counter-intuitive),

:)

> and sounds like
> a serious problem in it's own right. If a null return value produces
> this error message too, then the error message is horribly unfair to the
> standard non-velocity java programmer... Java as a language has a
> fundamental philosophy of explicitly catching and outputting an error
> message on null's, leading to "NullPointerException" being one of the
> most frequently encountered for novice/intermediate programmers (and
> maybe it shouldn't, but the fact is it does, and people kind of expect
> java systems to honour that philosophy).

i'm gonna disagree here.  VTL (velocity template language) is not java and
should not be expected to be so.  please note that it will respond precisely
the same if $account itself is null.  it's just trying to tell you that the
reference, whether ${ref} or ${obj.ref} is not going to render properly.

this is why silent notation (e.g. $!ref) exists.  if you just do $ref and it
is null, then the user will see $ref in the template.  this is bad practice
and could potentially even expose sensitive information about the inner
workings of your app.  so, if you have a reference (whether $ref or $obj.ref)
that you can reasonably expect to return or be null, then you should be using
silent notation.  this is essentially what the warning is trying to tell you,
though i readily confess that it isn't clear from the message.


> That error message ought at least to make explicit mention of null as a
> possible cause, since null is OFTEN a valid return value for
> applications - there is nothing wrong with logic that returns a null
> value in a java app, but velocity silently kills it. I can see the
> argument that in a templating engine perhaps null should never be
> returned - but that assumes this templating engine will never be
> attached to another system, and AFAICS velocity is proving extremely
> popular for attaching to other systems?

but there can be something wrong with displaying unrendered references in a
template language.  thus the warning message.

> I'm guessing an even better approach would be two separate messages, one
> for the "couldn't find a method" and another for "found a method but it
> returned null", and in both cases it ought to say what the method name
> it found (or tried to find) was. That would shortcut the debugging
> process considerably, and probably reduce the number of people in my
> situation who even needed to come to the list to ask for help :).

yeah, that sounds like a worthy enhancement request.  i'd recommend filing a
bug report on it so it doesn't get forgotten.  and, of course, if you can come
up with a patch to go with it, that would be cool too.  i can't say whether
it'll ever be applied, but i think this is a good idea.

Nathan Bubna
nathan@esha.com


---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org


Re: Velocity "is not a valid reference" error...help?

Posted by specialist33 <sp...@grexengine.com>.
Nathan Bubna wrote:
> specialist33 said:
> 
>>I'm getting an incomprehensible "is not a valid ref" error. I've spent
>>some hours trying to solve it, but I'm not being helped by the fact that
>>I cannot seem to find a way of getting velocity to tell me what WOULD be
>>a valid reference or WHY this is not a valid ref.
>>
>>summary == [it's a public method in a public class,
>>and i'm doing the VTL syntax properly,
>>but still getting error messages.  help!]
> 
> ...
> 
> ok, i agree.  you've got the public, public, public thing down, and you're
> getting most of your references right, so i either don't have a clue what the
 > problem is or else your getLogin() method is returning null.  can you 
assure
 > us that the latter is not the case?

It was sometimes returning null, so I made it forced return something 
(in this case the string "unquoted3" (quotes only there to illustrate, 
as the name suggests the value had no quotes ;)). That produced the 
following log statements:

[INFO]-I just put currentAccount = [package].BaseAccount@1cac6db into 
the context with getLogin = unquoted3

[INFO]-ResourceManager : found testcookie with loader 
org.apache.velocity.runtime.resource.loader.FileResourceLoader

[WARN]-org.apache.velocity.runtime.exception.ReferenceException: 
reference : template = testcookie [line 9,column 52] : $account.getLogin 
is not a valid reference.

(note that "testcookie" is the literal name of the template file being 
used here).

 > problem is or else your getLogin() method is returning null.  can you 
assure

! This possibility entirely passed me by (its probably in the docs and I 
just didn't notice it, but it's very counter-intuitive), and sounds like 
a serious problem in it's own right. If a null return value produces 
this error message too, then the error message is horribly unfair to the 
standard non-velocity java programmer... Java as a language has a 
fundamental philosophy of explicitly catching and outputting an error 
message on null's, leading to "NullPointerException" being one of the 
most frequently encountered for novice/intermediate programmers (and 
maybe it shouldn't, but the fact is it does, and people kind of expect 
java systems to honour that philosophy).

That error message ought at least to make explicit mention of null as a 
possible cause, since null is OFTEN a valid return value for 
applications - there is nothing wrong with logic that returns a null 
value in a java app, but velocity silently kills it. I can see the 
argument that in a templating engine perhaps null should never be 
returned - but that assumes this templating engine will never be 
attached to another system, and AFAICS velocity is proving extremely 
popular for attaching to other systems?

I'm guessing an even better approach would be two separate messages, one 
for the "couldn't find a method" and another for "found a method but it 
returned null", and in both cases it ought to say what the method name 
it found (or tried to find) was. That would shortcut the debugging 
process considerably, and probably reduce the number of people in my 
situation who even needed to come to the list to ask for help :).

---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org


Re: Velocity "is not a valid reference" error...help?

Posted by Nathan Bubna <na...@esha.com>.
specialist33 said:
> I'm getting an incomprehensible "is not a valid ref" error. I've spent
> some hours trying to solve it, but I'm not being helped by the fact that
> I cannot seem to find a way of getting velocity to tell me what WOULD be
> a valid reference or WHY this is not a valid ref.
>
> summary == [it's a public method in a public class,
> and i'm doing the VTL syntax properly,
> but still getting error messages.  help!]
...

ok, i agree.  you've got the public, public, public thing down, and you're
getting most of your references right, so i either don't have a clue what the
problem is or else your getLogin() method is returning null.  can you assure
us that the latter is not the case?

Nathan Bubna
nathan@esha.com


---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org