Get the tools you need to learn Java skills fast!
Video tutorials, eBooks, hands-on lab exercises, sample code.
Get started
The moose likes EJB and other Java EE Technologies and the fly likes Field validation in session beans? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of The Software Craftsman this week in the Agile forum!
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "Field validation in session beans?" Watch "Field validation in session beans?" New topic

Field validation in session beans?

R van Vliet
Ranch Hand

Joined: Nov 10, 2007
Posts: 144
Hi all,

I have a question. I'm working on some EJB3 session beans which are the business logic for a few JSF pages. Currently, both the JSF pages as well as my methods seperately check if certain method parameters conform to specific rules (length min/max, matches specific regex, etc.). I dont like having to do this twice but since the beans can be called from places thay may not do such validation I dont have much of a choice.

My question is this; is there a neat way to define such rules once and use them in both the beans and the JSPs? Is there a best practice for this?

Hope someone can help me out,


Jeanne Boyarsky
author & internet detective

Joined: May 26, 2003
Posts: 31680

You could put the rules in a utility class and call it from two places. It's good to be doing validation in places other than a JSP though (like the JSF Java code.)

[OCA 8 book] [Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
I agree. Here's the link:
subject: Field validation in session beans?