This week's book giveaway is in the JavaScript forum.
We're giving away four copies of Svelte and Sapper in Action and have Mark Volkmann on-line!
See this thread for details.
Win a copy of Svelte and Sapper in Action this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

moving Struts validation into an external javascript file

Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
Whoever got anywhere by being normal? Just ask this exceptional tiny ad:
Thread Boost feature
    Bookmark Topic Watch Topic
  • New Topic