• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

When To Validate Against Database?

James Ellis
Ranch Hand
Posts: 205
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?

  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic