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?
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.
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.
With this you make two problems from one problem instead of solve one problem.
Robin Sharma
Ranch Hand
Joined: Aug 24, 2005
Posts: 76
posted
0
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
posted
0
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
posted
0
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://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to
run our stuff on 16 servers instead of 3.
subject: Creating a utility managed bean, to move common code and use from different beans?