This week's book giveaway is in the Agile and other Processes forum.
We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line!
See this thread for details.
The moose likes JSF and the fly likes When To Validate Against Database? Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » JSF
Reply Bookmark "When To Validate Against Database?" Watch "When To Validate Against Database?" New topic
Author

When To Validate Against Database?

James Ellis
Ranch Hand

Joined: Oct 14, 2004
Posts: 205
I am creating my first real JSF app which allows a user to create an email account. I have a page that has these fields:



And my architecture looks like this:

com\myapp\model\EmailBean.java - Bean containing getters and setters for fields above.
com\myapp\model\EmailHandler - Contains methods for connecting to the database to perform CRUD operations for email accounts.
com\myapp\controller\EmailPreferencesController.java - Contains an "emailBean" property of type "EmailBean" and a getter/setter for this property. This class also contains an action "createEmail" which calls methods from EmailHandler to create the email in the database.

My question is...where do I check if the email already exists in the database? In the method createEmail? If so, how do I get the error message back to the jsf page since the only thing I am passing this method is the instance of EmailBean.

I have thought about writing a validator to check if it exists in the database, but if it does then I'd need to write it to the database in another phase which would take place after (albeit only a split second) but still not really in a transaction.

So when do I check if the values exist in the database and how do I notify user that they do exist?

Thanks,
Jim
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: When To Validate Against Database?
 
Similar Threads
Customizing validations-h:message
message required
<rich:ajaxValidator>
How h:message and h:messages work
JSF 1.2 doesn't display in IE 8