Skip to main content

How I list/get all managed beans or ManagedBeanBean ?

4 replies [Last post]
trematodeo
Offline
Joined: 2010-02-19

Hello all!

I need to find a way to get all beans from the jsf environment. I don't want to read from faces-config.xml.

Now I'm using icefaces (jsf1.2) and I found that all beans names are loaded into the ManagedBeanBean class. How I can get all of these ManagedBeanBean classes from the jsf?

Now I'm listing each bean in my listener, but this isn't a good aproach. If I can load from the jsf will be possible to make this service automatic.

Thanks

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
trematodeo
Offline
Joined: 2010-02-19

There are a way to get a FacesConfigBean instance?

trematodeo
Offline
Joined: 2010-02-19

I found that if I set Util.setUnitTestModeEnabled(true) then I can get the FacesConfigBean from the context:
FacesConfigBean fcb = (FacesConfigBean)context.getAttribute("com.sun.faces.FACES_CONFIG_BEAN");

But was necessary change the source code. Another option is to load (or reload) the faces-config.xml. I'm trying don't do this because if we change to jsf2.0 then maybe the faces-config.xml will not exist.

Any sugestion?

manuelbernhardt
Offline
Joined: 2010-07-15

Hi,

> I found that if I set
> Util.setUnitTestModeEnabled(true) then I can get the
> FacesConfigBean from the context:
> FacesConfigBean fcb =
> (FacesConfigBean)context.getAttribute("com.sun.faces.F
> ACES_CONFIG_BEAN");

I'm not really sure why you need all the beans of your application, but it looks to me that what you're doing might not be the best way. In other words, calling Util.setUnitTestModeEnabled(true) may have a number of side-effects that you wouldn't want to have in a production environment.

If the design of your application really does require you to have access to all bean instances, then I would advocate using a mechanism that uses the default (empty) constructor of the beans, like e.g.:

[code]
public MyBean() {
BeanCollector.collect(this);
}
[/code]

With BeanCollector holding a static collection (which you may want to put in a ThreadLocal).

Manuel

trematodeo
Offline
Joined: 2010-02-19

Thanks manuelbernhardt, excellent sugestion!