File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Struts and the fly likes how to validate data Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "how to validate data" Watch "how to validate data" New topic

how to validate data

rames tirrupur

Joined: Jul 25, 2006
Posts: 13
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.

Merrill Higginson
Ranch Hand

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

Consultant, Sima Solutions
Gilbert johnson
Ranch Hand

Joined: Jul 10, 2005
Posts: 45
If you dont want to use form beans validate can use struts validation framework to do the validations for already has built in validations for a lot of cases

But dont do it in the action class.....thats bad practice. And it doesnt even make sense
I agree. Here's the link:
subject: how to validate data
It's not a secret anymore!