aspose file tools*
The moose likes JSF and the fly likes Creating a utility managed bean, to move common code and use from different beans? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSF
Bookmark "Creating a utility managed bean, to move common code and use from different beans?" Watch "Creating a utility managed bean, to move common code and use from different beans?" New topic
Author

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

Robin Sharma
Ranch Hand

Joined: Aug 24, 2005
Posts: 76
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:


DW
There is always a bug :-)
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16250
    
  21

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?


Customer surveys are for companies who didn't pay proper attention to begin with.
Darryl Nortje
Ranch Hand

Joined: Jun 11, 2002
Posts: 140
A singleton??
Bauke Scholtz
Ranch Hand

Joined: Oct 08, 2006
Posts: 2458
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

Joined: Oct 08, 2006
Posts: 2458
Darryl Nortje wrote:A singleton??

With this you make two problems from one problem instead of solve one problem.
Robin Sharma
Ranch Hand

Joined: Aug 24, 2005
Posts: 76
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

Joined: Aug 24, 2005
Posts: 76
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

Joined: Oct 08, 2006
Posts: 2458
Honestly, there is a smell in the technical design.

What´s the functional requirment for which you need this?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Creating a utility managed bean, to move common code and use from different beans?