File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JSF and the fly likes Should I bean this? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSF
Bookmark "Should I bean this?" Watch "Should I bean this?" New topic

Should I bean this?

Rob Micah
Ranch Hand

Joined: Aug 30, 2011
Posts: 94
I have a SessionScoped ManagedBean that holds an ArrayList of a custom class. In my facelet I reference this custom class in components. I previously had this custom class defined as a sub-class of my bean:

But the codebase for the custom class is getting complex and so I moved it to its own file. This appears to work. So my question is should I have declared this custom class as a bean since it has get/set methods and if so how would I instantiate it in my SessionScoped bean class since this will be inside a List?
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16539

CustomClass is a bean (POJO), and always has been a bean, although perhaps not literally a POJO, since it was an embedded class.

I think what you're asking is should it be a Managed Bean. And the answer to that is no.

A Managed Bean isn't a class, it's a unique instance of a class, accessible by name and constructed automatically by JSF.

Since CustomClass is not being used as a single unique instance - instead you have an entire collection of CustomClass objects, the bean management mechanisms would only apply if you went to the not-inconsiderable effort of adding a whole lot of managed CustomClass instances to your faces-config file (Annotations can't deal with multiple instances), and then fed the references to all those instances to the target bean's constructor as a managed collection property. Which is probably not going to be flexible enough for most purposes.

Customer surveys are for companies who didn't pay proper attention to begin with.
I agree. Here's the link:
subject: Should I bean this?