You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by Eric Fixler <fi...@fixler.com> on 2004/11/10 11:33:08 UTC

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
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 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