title: Saving data to session in JSF
body: <p>I am new to the world of J(2)EE and web app development but am quickly navigating my way around it and learning a lot. Every day is a fantastic voyage of new discovery for me.</p>
  
  <p>I am currently working on a project in which I am using Visual JSF Woodstock on Glassfish v2. I am pretty new to JSF also. </p>
  
  <p>There are times when I need to save some objects (say MyObject for instance) between requests. And from what I have read and understood so far, I need to be using sessions to save these objects between different requests. So far so good.</p>
  
  <p>Exactly how to do this is where my concern lies. I know that in JSP you can use the <code>session.setAttribute("myObj", myObject)</code> which would save the object at client side using cookies or url rewrites or hidden form variables. </p>
  
  <p>On the other hand, in JSF I use Session scoped beans, say SessionBean1 for e.g., and save objects as SessionBean1 properties (e.g. <code>SessionBean1.setSomeOjb(myObj)</code>). Is this the right way to go about with this? </p>
  
  <p>I am guessing that doing it this way will result in increased memory utilization at the server end since each request will create a new instance of the session scoped bean, SessionBean1 plus the memory utilized by the saved myObject instances in SessionBean1.</p>
  
  <p>I have read that you can use <code>FacesContext.getExternalContext().getSession/getSessionMap()</code> which would save session variables at client side.</p>
  
  <p>So which method would you suggest that I use - the session scoped bean or the sessionmap to save objects for access between requests for a session?</p>
  
  <p>Thanks.</p>