• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Date Validation

 
Garandi Garandi
Ranch Hand
Posts: 192
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am trying to validate date, I have the following in validator-rules.xml,
but date validation does not work, although I have struts.jar in classPath and it has FieldChecks.class in it.
Thank you
Garandi

[ March 22, 2005: Message edited by: Garandi Garandi ]
 
Merrill Higginson
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You haven't shown us the entry in your validation.xml. It should look something like this:

 
Garandi Garandi
Ranch Hand
Posts: 192
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you for your reply, what is "<var-name>datePatternStrict</var-name>",and how am I going to use it.
Thank you in advance
Garandi
 
Merrill Higginson
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In order for the validation framework to validate your date, it must know what format you expect the date to be in. Internally, it uses java.text.SimpleDateFormat to do this. If you look up this class in the Java API, you will find that one of it's constructors requires a format string such as the one given in the <var-value>tag of the example I gave you. The API docs will also show you the list of valid characters in this string. The <var-name> and <var-value> in the validation.xml example simply pass a parameter into the validator.

One other thing: make sure that your struts-config.xml has the following entry:



Otherwise, the validator isn't even turned on.

I'd advise you to open up the struts-examples.war that came with the download and study the example of validation that is there. One example includes a data validation. That should help you to understand how all the pieces fit together.
 
Garandi Garandi
Ranch Hand
Posts: 192
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you very much.
Garandi
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic