0

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
cweston
  • 10,371
  • 17
  • 74
  • 104
  • I think this answer http://stackoverflow.com/questions/6377798/what-can-be-jsf-fmetadata-and-fviewparam-for/6377957#6377957 is what you are looking for – maks Oct 01 '11 at 09:10

1 Answers1

1

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
  • 7,644
  • 8
  • 49
  • 75