JSF Bean problem with HTTPSession

Discussions

Web tier: servlets, JSP, Web frameworks: JSF Bean problem with HTTPSession

  1. JSF Bean problem with HTTPSession (2 messages)

    Hi, I have a problem: All JSFBean are managed-bean-scope : session. But, this is a problem, therefore all the attributes of beans also are stored in the session and it has attributes of type List that it consultation the Data Base that returns many register. My session to be full and heavy! How solve this problem ? :(
  2. I'm not sure I understand your question, but you do realize that the available scoping is: none, application, session, and request, right?
  3. This is becomming a pretty classic JSF issue. There are a few options. 1. You can use JBoss seam but based on another thread recently in news seam does store the JSF conversation state in HTTP session. If you use seam then you can create a user context that you can place your bean. 2. You can take a look at apache orchestra. It is based on Spring and will store your bean using JPA. 3. You can create your own ELResolver that you can use to map the beans to where ever you want them to be using what ever technology you want. This is very straight forward to do. 4. Use a passive controller pattern. In this pattern all JSFBeans are controller objects. The list that you are storing can then be placed in some other store mechanism JPA, Cache, etc other than session. This pattern maps something like #{controllerBean.listBean.fieldName}. The controller bean holds a reference to listBean and the reference would be some sort of PK or Cache Key that gets your list back to you. public class Controller { private String _listPK; @PersistentContext private EntityManager em; public List getList() { List result = em.createQuery("Query with listPK"").getResultList(); if(result.size() > 0) em.persist(result); return result; } } This is just pusedo type code a few things you will have to handle like constructing the query and getting in initial listPK or handling initial case of listPK is null. This is a JPA example but the pattern can be used with other types of cache stores or SOA or what ever. One word of caution with JPA. If you list can change do NOT use JPA because it will break you code if the list contents change from the response to request post. In this case I would advise using a cache solution. I have written one for myself using encache and it is quite straight forward to do