Troy,

You may be interested in looking at Shale. (http://shale.apache.org/)
The shale view controller is an interface that gives you some extra
plug-in points in the JSF lifecycle.  One of these points is an init
call, which is guaranteed to run after your managed bean has been
constructed and had all of its dependencies injected.

For your list boxes you could also use the init method, or if you are
using the <f:selectItems> tag to populate your pulldowns, you could use
any method you wanted to populate the pulldowns as long as that method
was bound to the selectItems tag.  This method will get called everytime
you render though, so you would probably only want to do that if your
lists were changing every request.


JB

-----Original Message-----
From: Jeff Bischoff [mailto:[EMAIL PROTECTED] 
Sent: Monday, October 02, 2006 3:18 PM
To: MyFaces Discussion
Subject: Re: Backing Bean Constructor

Troy,

Yes, you can use the constructor for these tasks, if it suits you. I
would be cautious though, what I put in a managed-bean constructor. Keep
in mind that the class will be automatically instantiated by the
framework any time it is looked up or otherwise referenced. I've gotten
myself into trouble by over-using the constructors.

In our project, we do still use the contstructors to load any drop-down
lists that are rather static. For loading live data or dynamic
drop-downs, however, we steer clear and go in favor of a load() method
which is explicitly called as a result of the business logic set in
motion by the command action.

Our pattern is far from perfect - we're just adapting as we go. I'd
suggest you play around with it a bit, and see what works best. Don't
rule out the use of the constructor, but don't abuse it either! ;)

Regards,

Jeff Bischoff
Kenneth L Kurz & Associates, Inc.

Troy Bull wrote:
> Greetings
> 
> I have a faces page that allows the user to edit a table in the 
> database.  What I want to do is in the constructor of the backing bean

> load up some data from the database so that it can be displayed and 
> edited on the faces page.  Is this considered bad form?  Also just off

> the top of my head is this a place I can also load collections that 
> will be used for drop down list boxes?
> 
> Please help, I don't want to do things the wrong way...
> 
> Troy
> 
> 
> 


Reply via email to