• 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:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

validation.xml check date conflict (and when to use DynaActionForm)

 
Ranch Hand
Posts: 755
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi there,

does anyone know how to check if date A is before date B in the validation.xml file?

I think this is the drawback when using xml over ActionForm. with ActionForm the validate is simple java while xml has it's own rules.

conceptually speaking: when should I use DynaActionForm over normal bean?
:roll:
thanks
 
Ranch Hand
Posts: 425
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

when should I use DynaActionForm over normal bean?



I personally don't like using DynaActionForm. With a good IDE, you can write a JavaBean that is a subclass of ActionForm just as quickly and easily as you can write the XML for the DynaActionForm properties. The thing I hate most about DynaActionForm is the way you retrieve properties.

is uglier and more error prone than
 
Ranch Hand
Posts: 948
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I agree with Merrill on DynaActionForm. The syntax to get at the fields is just too ugly and error prone. Sure you don't have a bunch of form classes floating around but all you have done is move the code from Java into XML and made your struts-config file larger.

I actually put a fair amount of code into my action forms. I generally have code in there that knows how to populate the form from a DTO and how to populate a DTO from the form. I also treat my form as a "view helper" class so I might have a method like getFormattedName() that concatenates first, middle and last names. Generally if I can move logic or scriptlets out of a JSP an put them into the form I feel I am better off.

- Brent
 
Did you miss me? Did you miss this tiny ad?
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic