Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

JSF PrimeFaces: Request Session being lost on each GUI interaction  RSS feed

 
Luis Rocha
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi friends, please help me with this, I have been fighting with this problem for some days and now its urgent for me to get this working.

I have a legacy Tomcat app that uses servlets and JSPs. on Each servlet the user access is being checked by reading a variable from the session. That works great but....

I am invoking an xhtml from the servlet or by typing the url in the browser. When the manager gets in the postConstruct mehod, I can read that session variable and its fine, then I go to the page and type anything into a input, when I check the setter method inside the manager the request.getSession () returns null.

In other words, the session variable inside the given request exists only in the postconstruct but after any interaction with the user the request variables is turned into null. The same happends with the request attributes. Only Params remains.

Any Ideas???

 
Tim Holloway
Bartender
Posts: 18705
71
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the JavaRanch, Luis!

In JSF, you should rarely need to obtain the HttpRequest and HttpResponse objects or do much else with FacesContext. JSF does most of its work from outside, so the more code that you have that uses javax.faces classes, the more it is likely that you are doing something the wrong way.

In particular, session objects do not need to be hunted down and read because you can simply define them as Managed Property objects and JSF will automatically inject them into the Managed Beans. JSF session objects and legacy J2EE session objects are the same thing. The only difference between them is that if you name a session object as a Managed Bean, JSF will automatically create one (using a no-arguments constructor) if one does not already exist.

I suspect that your real problem here, however, is that you probably have your bean defined in Request Scope. In JSF, Request Scope is almost 100% useless. Request Scope beans get destroyed and re-created on JSF postbacks, so data stored in them will be lost. Use View Scope or Session Scope, instead.
 
Luis Rocha
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thans Tim for your reply. In fact Iam using a view scoped bean for my page. The problem is not in the jsf but on the next servlet.

From my managed bean I must call to a legacy servlet that needs that session variable to work. When I redirect to that page none of the attributes nor the session is on the request. I could use a session scoped bean to put some things but the problem is not the jsf itself.
 
Tim Holloway
Bartender
Posts: 18705
71
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
View scoped beans are a special hack of session scope. JSF deletes them from the session when you navigate to a new view (xhtml). So you might as well just make the bean session scope.
 
Luis Rocha
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Will the session scoped bean keep the session and attributes of the request object when I go from the xhtml to the servlets again???
 
Tim Holloway
Bartender
Posts: 18705
71
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is only one HttpSession object per user client. If I ran IE and Firefox on the same client computer, they would not share a session, but all Firefox windows would share the same session and all IE windows would share the same IE session.

Request scope data would be lost, but that's because Request scope is transient. Session scope data would be available for until the user logged off, the session timed out, or the application explicitly deleted the data.

Make sure that all your session-scope objects are Serializable, though. That's not just a JSF restriction, it applies to J2EE/JEE in general. If a non-serializable component is stored in a session object, it may get deleted at any time. Some servers won't even allow it to be done at all.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!