aspose file tools*
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
Author

how to validate data

rames tirrupur
Greenhorn

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.

Thanks,
Ramesh
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.


Merrill
Consultant, Sima Solutions
Gilbert johnson
Ranch Hand

Joined: Jul 10, 2005
Posts: 45
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: how to validate data
 
Similar Threads
Can I validate my form using Struts-Portlet framework functionality
loose the user-inputs when maxLengthExceeded by a file upload
Form Validations in Spring
strut validation frame work issue
about the validation