Good question. I hope apart from me more people will share either knowledge on this topic. On your questions.
1. How to check if date1 is less than date2 in validation.xml?
I don't see any predefined tag/element to do this. However this can be achieved if you can write custom validator class. In the below URL look for "Comparing two fields" section.
http://struts.apache.org/1.x/faqs/validator.html Personally I don't see how much we gain by writing custom validator unless the validation has to carried out in dozen of forms. Even in these cases it makes sense to have utility class/method and delegate the specific validation to this class.
2. When to use XML (validator plugin) and ActionForm validate() method.
The real advantage of validator plugin is it's capability to perform both
- Server-side validation
- Client-side validation.
Particularly if your application needs to run on multiple browsers with straight forward client-side validation then validator saves you a lot of pain. Not everyone may agree with the point that we should try to restrict standard validator attributes provided in
struts.
I prefer client-side validations to be simple check and server-side validation to be exhaustive. The ideal solution (as far as I can think) will be to
- Use validator plugin and define rules (primarily for client-side)
- Let the action form extend ValidatorActionForm but override validate() method and call super.validate() to perform validations done on client-side to be carried on server-side and additional complex validations which is not easy to configure in validator plugin (without writing custom validator).
- One overhead I can think of is if form is being used by multiple actions then validate() method will be big to cover each action unless it is modularized.
Honestly I haven't tested this approach but this is now my priority
.
3. Between DynaActionForm and ActionForm?
I haven't seen many applications really using DynaActionForm. My exposure to DynaActionForm is very limited.
Hope to see how other's look at these questions.
[ October 31, 2006: Message edited by: Purushothaman Thambu ]