• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

What is the best managed bean design in my case?

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I have two entities say A and B. A has a one to many relationship with B. I want to produce a simple crud for my entities.
B operations must be carried out via A. For example if I want to add one B to an existing A I should do the following:
B b = new B();
a.add(b);
ADao.update(a);

Bs don't have any meaning outside A.

Here comes my question:
What is the best approach regarding the design of managed beans?
1. One managed bean for A which manages all A and B operations.
2. One managed bean for A and one managed bean for B. These managed bean are nested. AManagedBean has an Instance of BManagedBeans. (I don't know if this approach is normal or not)
3. Like number 2 but managed beans are separated and communicate vie JSF facilities.

Or there is a more straight solution here? What if B has a one to many relationship with C!

I'm waiting to hear your suggestions!
 
Saloon Keeper
Posts: 27807
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think the first thing to determine is what kinds of beans you're working with. The JSF framework as it presently exists works best on managing backing beans. It's not very handy at managing datamodel or other behind-the-scenes beans.

On the other hand, the Spring Framework is good at managing datamodel, dao/service, and other non-backing JavaBeans, but it's not JSF-aware.

There's obviously room for improvement there. At present, I have 2 separate config files, one for JSF and one for Spring, and a glue bean (resolver) that links the 2. Hopefully someday someone will come up with a cleaner approach. Aside from the need to keep 2 distinct configurations, there's enough overlap between functionalities that in some cases, it's equally valid to use either of the 2 mechanisms.

Most, though not all, situations where you have a one-to-many relationship are more appropriate for Spring, especially if you have a parent/child datamodel and a service bean to manage their relationships. But that doesn't mean that there's only one solution.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic