aspose file tools*
The moose likes Struts and the fly likes Pros & Cons of putting validation helpers in ActionForm Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Pros & Cons of putting validation helpers in ActionForm" Watch "Pros & Cons of putting validation helpers in ActionForm" New topic
Author

Pros & Cons of putting validation helpers in ActionForm

Junilu Lacar
Bartender

Joined: Feb 26, 2001
Posts: 4714
    
    7

In my current project I am trying to promote the use of org.apache.commons.lang utility classes to help do input validations for forms (still working towards getting the team to use the Validator). Right now there are a number of helper methods in the base ActionForm and more are getting added as I write.
Examples of what I'm trying to do:
- deprecate BaseForm.isEmpty(String); use
org.apache.commons.lang.StringUtils.isBlank(String) instead
- deprecate BaseForm.isIntegral(); use
org.apache.commons.lang.StringUtils.isNumeric(String) or
or ...lang.math.NumberUtils.isDigits(String) instead

I'd like to put together a list of pros and cons of the current practice, hoping to show that there are more cons than pros.
The only pro right now is convenience - you don't have to import another class; you can just call the method directly.
The cons I have are:
1. Methods like these really should be in a statics-only Utility type class (thus the push to use commons.lang classes).
2. The methods pollute the BaseForm object.
3. The validation code is coupled to the Form (right now they're instance methods). If you want to reuse the validation code somewhere else, it won't make sense to instantiate a form then call the method. (Of course it would be argued that doing so would be silly and that a solution would be to make the methods static, but still keep them in the Form. Still bad but I just know it's going to be said).
My concern is that it can be argued that these (both pro and cons) are just a matter of aesthetics/form; that there is really no advantage or disadvantage of doing it one way or the other. I know there must be other more compelling reasons against the current practice but I can't seem to find the right search criteria to find them.
Any help or suggestions would be appreciated.
[ February 12, 2004: Message edited by: Junilu Lacar ]

Junilu - [How to Ask Questions] [How to Answer Questions]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Pros & Cons of putting validation helpers in ActionForm