myfaces-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bansi <mail2ba...@yahoo.com>
Subject RE: How to Share Session between JSF(MyFaces) and Spring
Date Thu, 17 May 2007 18:14:38 GMT

Hi Kito
Thanks for quick response. The reason Spring beans need direct access to
session object is to perform some business logic based on userId and user
Roles stored in session object. Hence the need to pass the session object
from JSF to Spring.  As you suggested i already implemented injecting Spring
beans into JSF managed beans via managed-property in faces-config.xml. And i
am able to successfully call Spring bean method  i.e.
getUserSession(userSession) to pass the session object to Spring layer. But
this call is limited to single Spring Bean. How if i wanna use same session
object in other spring beans . 
Here are the limitations of this approach
- Redundant code in each  Backing bean calling Spring bean to pass session
object
- Is it recommended to pass HttpSession object to business (Spring) layer
- Is it recommended to store userId and user Role in HttpSession object
inside JSF Backing Bean. My requirement is all my Spring beans perform
business logic based on userId and user Roles
- The reason i put question mark on HttpSession object is even within JSF
backing beans session is lost. For example i construct  session object in
LoginBean and when i try to retrieve session in other backing bean it
returns null. So i have to do something like this in the constructor of
backing bean
if(userSession == null){
		  System.out.println("Inside Manuf Constructor userSession");
	  userSession =
          (HttpSession)
FacesContext.getCurrentInstance().getExternalContext()
                                    .getSession(true);
	  Object sess = userSession.getAttribute("userId");
	  System.out.println("userId in Session="+sess.toString());
- Also the constructor of backing bean doesnt allow me to make a call Spring
bean and results in Null Pointer Exception. So not sure where exactly in the
backing bean i should make a call to getUserSession() method of Spring. For
test purposes i am making this call from register() method of backing bean
Overall i didnt have good success stories to share with by adopting this
approach. Any pointers/suggestions will be highly appreciated

Regards
Bansi
 


Kito D. Mann wrote:
> 
> Hello Bansi,
> 
> You can inject Spring beans into your JSF managed beans via the Spring
> DelegatingVariableResolver. Given that, you should be able to call your
> Spring bean methods and pass in the appropriate parameters. Why do your
> Spring beans need direct access to the session?
> 
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> Kito D. Mann (kmann@virtua.com)
> Author, JavaServer Faces in Action
> http://www.virtua.com - JSF/Java EE consulting, training, and mentoring
> http://www.JSFCentral.com - JavaServer Faces FAQ, news, and info
> 
>> -----Original Message-----
>> From: bansi [mailto:mail2bansi@yahoo.com]
>> Sent: Thursday, May 17, 2007 12:22 PM
>> To: users@myfaces.apache.org
>> Subject: How to Share Session between JSF(MyFaces) and Spring
>> 
>> 
>> Hi Gurus
>> Could you please tell me
>> What are the best practices to  pass Session object from JSF to Spring.
>> For
>> example lets say  LoginBean in JSF has to store userId and userRole in
>> Session object and then pass Session object to Spring Layer so that it
>> can
>> be accessible by any spring bean
>> 
>> - Do you recommend using Httpsession?
>> 
>> - Does OpenSessionInViewFilter provides a mechanism to store userId &
>> userRole in session & then pass it onto spring layer
>> 
>> OR
>> 
>> - Is their any other mechanism that you would recommend for storing
>> userId &
>> userRoles into Session object at JSF Layer and then retrieve the same
>> Session object at Spring layer so that it can be accessible by an
>> spring
>> bean
>> 
>> Any pointers/suggestions will be highly appreciated
>> 
>> Regards
>> Bansi
>> 
>> --
>> View this message in context: http://www.nabble.com/How-to-Share-
>> Session-between-JSF%28MyFaces%29-and-Spring-tf3772789.html#a10667077
>> Sent from the MyFaces - Users mailing list archive at Nabble.com.
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/How-to-Share-Session-between-JSF%28MyFaces%29-and-Spring-tf3772789.html#a10669495
Sent from the MyFaces - Users mailing list archive at Nabble.com.


Mime
View raw message