This week's book giveaway is in the OCAJP 8 forum.
We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line!
See this thread for details.
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 OCA Java SE 8 Programmer I Study Guide this week in the OCAJP 8 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: 32633

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]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2
I agree. Here's the link:
subject: Field validation in session beans?
jQuery in Action, 3rd edition