tags:

views:

150

answers:

1

I need to be able to grab a user's information from a database and pre populate some fields on the page from this information, using args sent in a GET request in the database's query.

What is the best way of performing this "on page load" type of functionality using standard JSF?

Couple possibilities I have found so far:

  • performing the initialization in the backing bean constructor (not a huge fan since I'd be making database calls from the constructor)
  • Using a phase listener
+1  A: 

My suggestion (If I am guessing correct what you are trying to accomplish) is

  1. When the user logs-in you create a backing bean with his/her information. Thus the DB code is in the action method that holds the login business logic.
  2. Whenever you need this information in any jsf web page you just inject this info bean to the backing bean behind your page using the normal injection mechanism of faces-config.xml for backing beans.

With this approach you do not need a phase listener, and the DB code is not in a constructor of a backing bean but in an action method (as it should).

kazanaki