• 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 ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

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: 28319
210
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.

 
It looks like it's time for me to write you a reality check! Or maybe a tiny ad!
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic