• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
  • Mikalai Zaikin

Should I bean this?

Ranch Hand
Posts: 108
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
Saloon Keeper
Posts: 27861
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.

With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
    Bookmark Topic Watch Topic
  • New Topic