Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Rex Norm
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • 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

 
Jesus Mireles
Ranch Hand
Posts: 122
IntelliJ IDE Java Mac
  • Mark post as helpful
  • send pies
  • 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.
 
Joe Ess
Bartender
Posts: 9280
10
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • 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.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64833
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic