• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how to do validation?

 
Liz Brown
Ranch Hand
Posts: 112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have 2 fields on my jsp:
start date and end date.
I have to put some validation that the startDate user enters in always less than or equal to the end date.
(I have myAction which extends ValidatorForm. I am using validation.xml to put required field check.)
 
Nathaniel Stoddard
Ranch Hand
Posts: 1258
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It sounds like you already know how to do validating for your ActionForm. What part exactly are you having problems with? Also, have you read the Struts documentation on build in validators for the ValidatorPlugin?
 
Liz Brown
Ranch Hand
Posts: 112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i have same problem.
I have startdate, end date.
I have validator.xml. (using validation plugin)
I have put both as required fields in this file.
but how to check if one is greater than another?
 
alan do
Ranch Hand
Posts: 354
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you need to write your own custom validation. look for samples online. the most common example you'll find is the validate identical (eg. if the user entered the same password for 2 fields). base on that example, you can do your date compare validation.
 
Liz Brown
Ranch Hand
Posts: 112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Has anybody done this before? Could you please point me to some useful information on what I am looking for.thanks.
 
Anything Possible
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It looks like someone took the time to document the solution at http://www.junlu.com/msg/159728.html
 
alan do
Ranch Hand
Posts: 354
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
every struts developer should have a shortcut to http://struts.apache.org/userGuide/index.html

for your question, look at the validatTwoFields example in the validator docs: http://struts.apache.org/userGuide/dev_validator.html
 
MInu
Ranch Hand
Posts: 517
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Write a small function for testing if the first date is greater than the second one.
then add the error to action error object.(valErrors.add("date", new ActionError("errors.date"));
 
Jason Menard
Sheriff
Posts: 6450
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by vinod:
Write a small function for testing if the first date is greater than the second one.
then add the error to action error object.(valErrors.add("date", new ActionError("errors.date"));


"vinod",

We don't have many rules here, but we do have a naming policy which we try to strictly enforce. Please re-read this document and edit your display name in order to comply.
 
MInu
Ranch Hand
Posts: 517
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic