Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
  • Piet Souris
  • Frits Walraven
  • Carey Brown

how to validate data

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.

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.
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
You can thank my dental hygienist for my untimely aliveness. So tiny:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
    Bookmark Topic Watch Topic
  • New Topic