You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Antony Stubbs <an...@gmail.com> on 2007/05/09 23:56:29 UTC

[S1] Struts JavaScript Validation staticJavascript generates too much code

Having staticJavascript=true generates *all* the validation functions
specificed in struts-validators.xml (?) even if the form it's generating for
only uses the REQUIRED validator. 

Is there a way to minimise the javascript generated?

I'm going to try a work around, where I've extracted the generated
javascript, and have put it in an external file that I will reference. Once
I've decided which functions I am not going to use, I will remove them from
this file.
-- 
View this message in context: http://www.nabble.com/-S1--Struts-JavaScript-Validation-staticJavascript-generates-too-much-code-tf3718534.html#a10403586
Sent from the Struts - User mailing list archive at Nabble.com.


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


Re: [S1] Struts JavaScript Validation staticJavascript generates too much code

Posted by Paul Benedict <pb...@apache.org>.
Antony,

The preferred way is to copy the static javascript into a static file (.js)
and include it as a <script> element. This will also allow it to be cached
by your browser. There's no reason why you must generate those functions
every time. The only generation must be for your form.

Paul

On 5/9/07, Antony Stubbs <an...@gmail.com> wrote:
>
>
> Having staticJavascript=true generates *all* the validation functions
> specificed in struts-validators.xml (?) even if the form it's generating
> for
> only uses the REQUIRED validator.
>
> Is there a way to minimise the javascript generated?
>
> I'm going to try a work around, where I've extracted the generated
> javascript, and have put it in an external file that I will reference.
> Once
> I've decided which functions I am not going to use, I will remove them
> from
> this file.
> --
> View this message in context:
> http://www.nabble.com/-S1--Struts-JavaScript-Validation-staticJavascript-generates-too-much-code-tf3718534.html#a10403586
> Sent from the Struts - User mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>

Re: [S1] Struts JavaScript Validation staticJavascript generates too much code

Posted by Niall Pemberton <ni...@gmail.com>.
On 5/9/07, Antony Stubbs <an...@gmail.com> wrote:
>
> Having staticJavascript=true generates *all* the validation functions
> specificed in struts-validators.xml (?) even if the form it's generating for
> only uses the REQUIRED validator.
>
> Is there a way to minimise the javascript generated?

Commons Validator 1.3.1 introduced a couple of things to help with this...

The first is that included in the Commons Validator jar are
"compressed" versions of all the validation script (for example as
well as validateRequired.js there is also a
validateRequired-compress.js) which are significantly smaller. Struts
1.3.8 shipped with a version of the validator-rules.xml file which is
configured with the compressed javascript (called
validator-rules-compressed.xml and can be found in
src/core/src/main/resources/org/apache/struts/validator)

See below for the second...

> I'm going to try a work around, where I've extracted the generated
> javascript, and have put it in an external file that I will reference. Once
> I've decided which functions I am not going to use, I will remove them from
> this file.

Validator 1.3.1 ships with two files which contain all the scripts
(compressed and uncompressed versions) which are in the binary
distribution:
  commons-validator-1.3.1.js
  commons-validator-1.3.1-compress.js

Niall

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


Re: [S1] Struts JavaScript Validation staticJavascript generates too much code

Posted by Laurie Harper <la...@holoweb.net>.
Antony Stubbs wrote:
> Having staticJavascript=true generates *all* the validation functions
> specificed in struts-validators.xml (?) even if the form it's generating for
> only uses the REQUIRED validator. 

That's why it's called 'static' :-) Think of it as library code.

> Is there a way to minimise the javascript generated?

Not other than through the technique you describe below.

> I'm going to try a work around, where I've extracted the generated
> javascript, and have put it in an external file that I will reference. Once
> I've decided which functions I am not going to use, I will remove them from
> this file.

That's why the staticJavascript option is there. This is a reasonable 
approach. Do remember to update the contents of the file if and when you 
upgrade to a different Struts release though. Personally I wouldn't 
worry about trimming that file down, since the browser should cache it 
and only have to fetch it the first time it's referenced.

L.


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