• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Rob Spoor
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
  • Scott Selikoff
Bartenders:
  • Piet Souris
  • Jj Roberts
  • fred rosenberger

Where is the best place to validate? XML, .validate() or JS? other?

 
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I've been struggling with this as a newbie...

should I validate input using the validate method? in XML using validator? via Javascript?

i'm trying to keep life simple for me, and I wonder what you guys think? has anyone done all 3 and can offer some wisdom as to what works best under which conditions?

Ideally, I'd like to go to one spot to validate and troubleshoot. As it is, I'm a little put off by the fact that Struts is not very easy to debug.

_R

 
Ranch Hand
Posts: 122
Mac IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In struts 1 I kept some of my validation in the validate method but in struts 2 I kept a lot of the simple validation with annotations.

I dont know that you want to particularly validate all your fields with JS as you can or may expose some of your internal rules to the client.
 
Bartender
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I usually use XML validation unless the validation logic is fairly complex, then I override the validation method.
Many people prefer JavaScript validation as it saves a round-trip to the server. I'm not working on apps with high traffic or latency, so a round-trip is fine for my purposes. Lucas has a good point about exposing your validation logic to the client.
The "best" validation strategy is the one that fills your requirements. It may seem confusing when you are just starting out, but one day you'll be glad you have a flexible framework.
 
Sheriff
Posts: 67642
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Validation should always occur on the server regardless of whether any client-side validation takes place. Client-side validation is easy to circumvent.

Client-side validation helps with the user experience (quick feedback, no server round-trip) but should never be relied upon. The server code should always pretend that client-side validation does not exist.
 
reply
    Bookmark Topic Watch Topic
  • New Topic