This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Struts and the fly likes moving Struts validation into an external javascript file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "moving Struts validation into an external javascript file" Watch "moving Struts validation into an external javascript file" New topic
Author

moving Struts validation into an external javascript file

George McCain
Ranch Hand

Joined: May 06, 2003
Posts: 35
Sorry but i'm sort of new to Struts, but i've noticed if you do javascript validation (using the )
it embeds about 36k worth of javascript into the page.
Sure, some part of it has to be dynamic according to your Form Name, but the rest are common validation functions that can be extracted out into an external .js file.
Does Struts support this?
if not i guess I can grab the latest code base and program this in.
but checking before I do that.
36k might not seem like that much, but thats about the size of 4 thumbnail images being sent for each page that uses struts javascript validation.

Thoughts?
Chris Elvart
Greenhorn

Joined: Feb 20, 2006
Posts: 9
I'm pretty new to struts to, but here is what I have figured out about this...

That 36k of stuff is code specified in the validation-rules.xml file. Think of it as the architecture behind client side validations. You need it if you want to do client side validations.

You could run this once, take the resulting text and put in in a .js file somewhere on your server and have the html include the rule like this...
<script language="JavaScript" src="/MyWebApp/Common/validatorRules.js"></script>

Hopefully the brower will cache that and not download it for each page, but that is not under your control.

The problem is that if you add a new validation rule you must remember to update the .js file you created.

Does that make sense? I think it does.
George McCain
Ranch Hand

Joined: May 06, 2003
Posts: 35
The problem with that is that in the call to generate the js

It will imbed the page with both logic for that form, and general checking logic.

So part of it does need to be dynamically generated for that particualar form , while a huge chunck of it can be copied and put in an external .js file.

I guess i'll just modify the source to do this.
Just checking to see if anyone else has noticed this or had a way around it.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: moving Struts validation into an external javascript file
 
Similar Threads
Struts validations of file path
error information using javascript
Validwhen validator client side javascript
Help with validation rules for form with multiple submit buttons
Validwhen validator java script