• 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
  • Ron McLeod
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

Creating a utility managed bean, to move common code and use from different beans?

 
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Howdy!

In my JSF managed beans, I frequently have the need to access some bean which is already in session, fiddle around with it and then set it back to the session. Could it be possible to create a managed bean which serves just as a utility class where the above and other common functionality could be hosted? Is it the right way or is there any other way to achieve the same?

Something like:
 
Saloon Keeper
Posts: 28714
211
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 don't understand. Regardless of whether a session bean is JSF-managed or managed via regular J2EE code, what are you trying to do?

It sounds like you're removing the bean from the session, modifying it, then returning it to the session. What's the point in removing/adding, when you can just leave the bean in the session and modify it in place?
 
Ranch Hand
Posts: 140
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
A singleton??
 
Ranch Hand
Posts: 2458
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Tim Holloway wrote:I don't understand. Regardless of whether a session bean is JSF-managed or managed via regular J2EE code, what are you trying to do?

It sounds like you're removing the bean from the session, modifying it, then returning it to the session. What's the point in removing/adding, when you can just leave the bean in the session and modify it in place?


Fully agree. Just get the reference and alter it. Do you know how collections/maps work? I would go through a decent Java book/tutorial which covers collections/maps. This is fairly trivial.

Back to your actual question: depends on the functional requirement, but in this case I think I would have used managed property injection.
 
Bauke Scholtz
Ranch Hand
Posts: 2458
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Darryl Nortje wrote:A singleton??


With this you make two problems from one problem instead of solve one problem.
 
Robin Sharma
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Guys, what I want is to centralize the code to get/set any bean in the session. The code I have shown above is getting repeated in many of beans. I want to avoid that.
 
Robin Sharma
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Tim Holloway wrote:I don't understand. Regardless of whether a session bean is JSF-managed or managed via regular J2EE code, what are you trying to do?

It sounds like you're removing the bean from the session, modifying it, then returning it to the session. What's the point in removing/adding, when you can just leave the bean in the session and modify it in place?



Tim, I use the setSessionBean method mainly to clear a bean from the session, by passing in null.
 
Bauke Scholtz
Ranch Hand
Posts: 2458
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Honestly, there is a smell in the technical design.

What´s the functional requirment for which you need this?
reply
    Bookmark Topic Watch Topic
  • New Topic