aspose file tools*
The moose likes Struts and the fly likes validation.xml  check date conflict (and when to use DynaActionForm) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "validation.xml  check date conflict (and when to use DynaActionForm)" Watch "validation.xml  check date conflict (and when to use DynaActionForm)" New topic
Author

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

Peter Primrose
Ranch Hand

Joined: Sep 10, 2004
Posts: 755
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
Purushoth Thambu
Ranch Hand

Joined: May 24, 2003
Posts: 425
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 ]
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
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


Merrill
Consultant, Sima Solutions
Brent Sterling
Ranch Hand

Joined: Feb 08, 2006
Posts: 948
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: validation.xml check date conflict (and when to use DynaActionForm)