Discussion:
Velocity "is not a valid reference" error...help?
specialist33
2004-10-10 15:02:48 UTC
Permalink
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
Shinobu Kawai
2004-10-10 15:46:43 UTC
Permalink
Hi, um... specialist33,
Post by 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 );)
## snip
Post by specialist33
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
Post by specialist33
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 <***@gmail.com>
specialist33
2004-10-10 15:49:25 UTC
Permalink
Post by Shinobu Kawai
Post by specialist33
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 ;).
Post by Shinobu Kawai
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
Shinobu Kawai
2004-10-10 16:18:34 UTC
Permalink
Hi specialist33,
Post by specialist33
i.e. they passed through unchanged, with the classic error message :((.
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 <***@gmail.com>
specialist33
2004-10-10 16:52:00 UTC
Permalink
Post by Shinobu Kawai
Hi specialist33,
Post by specialist33
i.e. they passed through unchanged, with the classic error message :((.
You know what? I haven't a clue...
#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 :).
Shinobu Kawai
2004-10-11 00:21:35 UTC
Permalink
Hi specialist33,
Post by specialist33
public java.util.Collection [package].BaseAccount.groups()
public java.lang.String [package].BaseAccount.getLogin()
Weird...
Post by specialist33
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.
Post by specialist33
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.)
Post by specialist33
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 <***@gmail.com>
Nathan Bubna
2004-10-11 02:02:12 UTC
Permalink
Post by specialist33
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
***@esha.com
specialist33
2004-10-11 14:37:36 UTC
Permalink
Post by Nathan Bubna
Post by specialist33
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]***@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).
Post by Nathan Bubna
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 :).
Nathan Bubna
2004-10-11 15:06:56 UTC
Permalink
Post by Nathan Bubna
Post by Nathan Bubna
Post by specialist33
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
Post by Nathan Bubna
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
the context with getLogin = unquoted3
[INFO]-ResourceManager : found testcookie with loader
org.apache.velocity.runtime.resource.loader.FileResourceLoader
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?
Post by Nathan Bubna
(note that "testcookie" is the literal name of the template file being
used here).
Post by Nathan Bubna
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),
:)
Post by Nathan Bubna
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.
Post by Nathan Bubna
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.
Post by Nathan Bubna
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
***@esha.com
Shinobu Kawai
2004-10-11 23:07:03 UTC
Permalink
Hi specialist33 & Nathan,
Post by Nathan Bubna
Post by Nathan Bubna
Post by Nathan Bubna
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. ;)
Post by Nathan Bubna
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. ;))
Post by Nathan Bubna
Post by Nathan Bubna
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 <***@gmail.com>
Nathan Bubna
2004-10-11 23:32:09 UTC
Permalink
Post by Shinobu Kawai
Post by Nathan Bubna
Post by Nathan Bubna
Post by Nathan Bubna
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. ;)
Post by Nathan Bubna
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. :)
Post by Shinobu Kawai
(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.
Post by Shinobu Kawai
Post by Nathan Bubna
Post by Nathan Bubna
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
***@esha.com
Shinobu Kawai
2004-10-12 01:19:16 UTC
Permalink
Hi Nathan,
Post by Nathan Bubna
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!
Post by Nathan Bubna
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.
Post by Nathan Bubna
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 <***@gmail.com>
Shinobu Kawai
2004-10-12 22:44:35 UTC
Permalink
Hi Nathan,
Post by Shinobu Kawai
Post by Nathan Bubna
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 <***@gmail.com>
specialist33
2004-10-11 15:18:48 UTC
Permalink
(last try; if the apache.org mailserver rejects this too I'm giving up)

Yup, it's working now. I'd mistakenly pruned out all the valid VTL
references and only left in the invalid one in the test case (blushes),
i.e. the opposite of what I'd intended to do :).

So, it was just the null that was causing the whole problem!

Thanks.
Post by Nathan Bubna
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.
Yup.
Post by Nathan Bubna
Post by specialist33
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
but there can be something wrong with displaying unrendered references in a
template language. thus the warning message.
Clarification: I'm arguing that because it often is valid, velocity
needs to go a little further in informing the developers that it has
happened.

I didn't mean to imply that velocity ought to always display "null" in a
template, but only that it ought to explicitly SOMEHOW be telling the
developer that a null was received.
Nathan Bubna
2004-10-11 15:38:10 UTC
Permalink
Post by specialist33
(last try; if the apache.org mailserver rejects this too I'm giving up)
Yup, it's working now. I'd mistakenly pruned out all the valid VTL
references and only left in the invalid one in the test case (blushes),
i.e. the opposite of what I'd intended to do :).
So, it was just the null that was causing the whole problem!
Thanks.
glad to help. :)
Post by specialist33
Post by Nathan Bubna
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.
Yup.
Post by Nathan Bubna
Post by specialist33
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
but there can be something wrong with displaying unrendered references in a
template language. thus the warning message.
Clarification: I'm arguing that because it often is valid, velocity
needs to go a little further in informing the developers that it has
happened.
I didn't mean to imply that velocity ought to always display "null" in a
template, but only that it ought to explicitly SOMEHOW be telling the
developer that a null was received.
understood. and it's a fair criticism. i'd say go ahead and file a bug
report. of course, i'm not a committer on the core, so i can't deal with it
for you, but i think it's a suggestion worth being kept track of (of course,
you should probably search and make sure it isn't already in bugzilla too. :)

Nathan Bubna
***@esha.com
Eric Fixler
2004-11-10 10:33:08 UTC
Permalink
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
***@fixler.com
Shinobu Kawai
2004-11-11 01:12:39 UTC
Permalink
Hi Eric,
Post by Eric Fixler
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.
## snip
Post by Eric Fixler
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 <***@gmail.com>
Eric Fixler
2004-11-11 04:52:33 UTC
Permalink
Hi Shinobu.
Post by Shinobu Kawai
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
***@fixler.com

David You
2004-11-10 16:48:05 UTC
Permalink
You have to put the FormBean name in the struts XML file. I got the same
problem, while I used to only provide bean name on the submit processing
action but not the form page action.

Regards
David

-----Original Message-----
From: Eric Fixler [mailto:***@fixler.com]
Sent: Wednesday, November 10, 2004 2:33 AM
To: Velocity Users List
Subject: Struts Javascript Validators

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
***@fixler.com


---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-***@jakarta.apache.org
For additional commands, e-mail: velocity-user-***@jakarta.apache.org
Eric Fixler
2004-11-10 17:20:41 UTC
Permalink
It's already there...if you mean this [the form name is
simpleSearchForm]

<form-bean
name="simpleSearchForm"
type="org.apache.struts.validator.DynaValidatorForm">
<form-property name="keyword" type="java.lang.String"/>
</form-bean>

eric
Post by David You
You have to put the FormBean name in the struts XML file. I got the same
problem, while I used to only provide bean name on the submit
processing
action but not the form page action.
Regards
David
-----Original Message-----
Sent: Wednesday, November 10, 2004 2:33 AM
To: Velocity Users List
Subject: Struts Javascript Validators
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.
- 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
(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
---------------------------------------------------------------------
---------------------------------------------------------------------
---------------------------------------------------------------------
Eric Fixler
***@fixler.com
David You
2004-11-10 17:56:59 UTC
Permalink
Not this one, mention the bean in the Actionmapping with
name="simpleSearchForm"

David


-----Original Message-----
From: Eric Fixler [mailto:***@fixler.com]
Sent: Wednesday, November 10, 2004 9:21 AM
To: Velocity Users List
Subject: Re: Struts Javascript Validators

It's already there...if you mean this [the form name is
simpleSearchForm]

<form-bean
name="simpleSearchForm"
type="org.apache.struts.validator.DynaValidatorForm">
<form-property name="keyword" type="java.lang.String"/>
</form-bean>

eric
Post by David You
You have to put the FormBean name in the struts XML file. I got the
same
problem, while I used to only provide bean name on the submit
processing
action but not the form page action.
Regards
David
-----Original Message-----
Sent: Wednesday, November 10, 2004 2:33 AM
To: Velocity Users List
Subject: Struts Javascript Validators
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.
- 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
(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
---------------------------------------------------------------------
---------------------------------------------------------------------
---------------------------------------------------------------------
Eric Fixler
***@fixler.com


---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-***@jakarta.apache.org
For additional commands, e-mail: velocity-user-***@jakarta.apache.org
Eric Fixler
2004-11-10 18:53:39 UTC
Permalink
Thanks for the reply...
Post by David You
Not this one, mention the bean in the Actionmapping with
name="simpleSearchForm"
It's mentioned in an action mapping here:

<action
path="/simpleSearch"
type="org.smete.exploratorium.action.SearchAction"
name="simpleSearchForm"
scope="request"
validate="true">
</action>

But, if my mental model of things is correct, the actionmapping isn't
referenced until the request is submitted, i.e. after the [dynamic]
javascript has already been written. (I tried adding an 'input'
parameter in the action, but this had no effect either)

BTW, validate true/false has no effect, I believe this refers to
server-side validation.

thanks...still trying
eric
Post by David You
-----Original Message-----
Sent: Wednesday, November 10, 2004 9:21 AM
To: Velocity Users List
Subject: Re: Struts Javascript Validators
It's already there...if you mean this [the form name is
simpleSearchForm]
<form-bean
name="simpleSearchForm"
type="org.apache.struts.validator.DynaValidatorForm">
<form-property name="keyword" type="java.lang.String"/>
</form-bean>
eric
---------------------------------------------------------------------
Eric Fixler
***@fixler.com
David You
2004-11-10 19:08:43 UTC
Permalink
Well, I mentioned in the first email, you need the name="simpleSearchForm"
not only in the submit action( Which is for the server validation), you also
need it in the action where you put you search parameters(For the javascript
validator).
Also the input name parameter is CASE sensitive(I fell for this one also).


David


-----Original Message-----
From: Eric Fixler [mailto:***@fixler.com]
Sent: Wednesday, November 10, 2004 10:54 AM
To: Velocity Users List
Subject: Re: Struts Javascript Validators

Thanks for the reply...
Post by David You
Not this one, mention the bean in the Actionmapping with
name="simpleSearchForm"
It's mentioned in an action mapping here:

<action
path="/simpleSearch"
type="org.smete.exploratorium.action.SearchAction"
name="simpleSearchForm"
scope="request"
validate="true">
</action>

But, if my mental model of things is correct, the actionmapping isn't
referenced until the request is submitted, i.e. after the [dynamic]
javascript has already been written. (I tried adding an 'input'
parameter in the action, but this had no effect either)

BTW, validate true/false has no effect, I believe this refers to
server-side validation.

thanks...still trying
eric
Post by David You
-----Original Message-----
Sent: Wednesday, November 10, 2004 9:21 AM
To: Velocity Users List
Subject: Re: Struts Javascript Validators
It's already there...if you mean this [the form name is
simpleSearchForm]
<form-bean
name="simpleSearchForm"
type="org.apache.struts.validator.DynaValidatorForm">
<form-property name="keyword" type="java.lang.String"/>
</form-bean>
eric
---------------------------------------------------------------------
Eric Fixler
***@fixler.com


---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-***@jakarta.apache.org
For additional commands, e-mail: velocity-user-***@jakarta.apache.org
Eric Fixler
2004-11-10 19:29:15 UTC
Permalink
I added the name parameter to the action that generate to the page that
displays the form. No effect.

I should also mention that the actual form is named 'simpleSearchForm'
and that, from the start, the dynamic java script wrote a function
called 'validateSimpleSearchForm', so I don't think it's a question of
the validator not knowing about the form...it just seemed to forget to
write the outer shell for a class called simpleSearchForm_required.

Anyway, thanks for the attempts at help, but it seems not destined at
the moment.

eric
Post by David You
Well, I mentioned in the first email, you need the
name="simpleSearchForm"
not only in the submit action( Which is for the server validation), you also
need it in the action where you put you search parameters(For the javascript
validator).
Also the input name parameter is CASE sensitive(I fell for this one also).
David
---------------------------------------------------------------------
Eric Fixler
***@fixler.com
Loading...