• Post Reply Bookmark Topic Watch Topic
  • New Topic

Pros & Cons of putting validation helpers in ActionForm  RSS feed

Junilu Lacar
Posts: 11155
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!