• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how to validate data

 
rames tirrupur
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All.

I need a clarification and suggestion.

I have a case where i need to capture all the user submitted values and do the validation for that values.

I know that in struts we should use form bean's validate method for doing it.

But, I dont want to user form bean.

Is it possible or a good idea to have validation logic in my business logic method.

What is the exact purpose of formbean?

Please provide some suggestions.

Thanks,
Ramesh
 
Merrill Higginson
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is the exact purpose of formbean?

In a nutshell, a form bean is the Java representation of the data on a single JSP page. Every variable data element of the page should also have a corresponding element in a form bean. Struts has a lot of utilities (the <html:xxx> tags for example) that automatically read from and write to the form bean. The idea behind this is that once the data has a Java representation, it's easy to pass it on to other classes for processing.

Because the form bean is closely tied to a page, it's a logical place to put simple validations. That's why most developers put simple validations such as "not blank", "integer only", etc. in the validate() method of the form bean, or have the Struts Validation Framework handle it.

If you really don't want to put any validations there, no law says you have to. It's just a convenient place to put them.

If you have more complex validations such as "account number must exist in the database", it's recommended to do those validations in your Action class and/or model classes.
 
Gilbert johnson
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you dont want to use form beans validate method.......you can use struts validation framework to do the validations for you.....it already has built in validations for a lot of cases

http://struts.apache.org/1.2.4/userGuide/dev_validator.html

But dont do it in the action class.....thats bad practice. And it doesnt even make sense
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic