-1

I have a simple page backed by a named bean. The page is also using primefaces, but I am not doing anything ajax in that page. The applications is hosted on Glassfish 5.1.

@Named("cardsView")
@RequestScoped
public class CardsViewBean implements Serializable {
   ...
}

This is the xhtml page. As you can see I am passing the bean to the master xhtml, not sure if it's the best practice or the source of the problem.

<ui:composition template="/fragment/master.xhtml"
    xmlns="http://www.w3.org/1999/xhtml"
    xmlns:h="http://xmlns.jcp.org/jsf/html"
    xmlns:p="http://primefaces.org/ui"
    xmlns:c="http://java.sun.com/jsp/jstl/core"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
    xmlns:ipc="http://java.sun.com/jsf/composite/component">

    <ui:param name="bean" value="${cardView}" />

    <ui:define name="content">
    .....
    </ui:define>

</ui:composition>

It is my understanding that the request scoped bean lives just for the request.

However when I look to the browser inspector I can see that each time I hit the page a new JSESSIONID is created. So I think that there is clearly something I have wrongly configured but I am not sure where to look.

BalusC
  • 992,635
  • 352
  • 3,478
  • 3,452
Leonardo
  • 9,275
  • 15
  • 43
  • 86
  • Your problem is not caused by JSF at all. I suggest to take a step back and learn how exactly sessions work. This is a good starting point: https://stackoverflow.com/q/3106452 This must give you new insights in order to be able to debug this on your own. – BalusC Apr 10 '20 at 09:01
  • Thanks @BalusC I know how sessions works :-) in fact it sounded strange that a new session is created. The problem is maybe that the application is deployed on a cluster, and my suspect is that instance are not sharing sessions. – Leonardo Apr 10 '20 at 09:19
  • If you already know how sessions work, why exactly are you trying to shove the fault onto a random MVC framework running on the server? You would have had faced still exactly the same problem when using any other MVC framework or even plain vanilla JSP/Servlet .. – BalusC Apr 10 '20 at 09:25
  • Because after investigation I have realized that the cluster are not talking to each others. The deployed app is based on JSF. Part of the original answer remains, why a @RequestScoped bean create a JSESSIONID ? The second part, why a new one is created each time is another issue. – Leonardo Apr 10 '20 at 09:33
  • `@RequestScoped` doesn't do that. You would have had exactly the same problem when using `@SessionScoped`, and it would incorrectly behave as if it's a `@RequestScoped`. – BalusC Apr 10 '20 at 11:30
  • OK, so where do I have to investigate in my code for solving this issue ? The bean is a @RequestScoped one, maybe it has some reference that is causing to behave the whole request/response as a session ? – Leonardo Apr 10 '20 at 11:56
  • Sorry, this question doesn't make sense to me. At least, JSF doesn't cause a new session to be recreated on every request. This is usually caused by misconfigration of server or proxy/loadbalancer. – BalusC Apr 10 '20 at 12:12
  • In the end I have removed Glassfish and installed Payara. It worked out of the box with the same cluster configuration. Regarding the JSESSIONID is now unique for all the requests. Still remain the fact that there is still a session. But as I am using Primefaces I suppose that the session is something that the framework does/need in background. I see in fact that it also store some cookie with component id reference. – Leonardo Apr 24 '20 at 05:55

1 Answers1

0

In fact, there is 2 request per page. Initial request and postback request. first, client makes a request to get the page. it is complete request by itself. request: http://example.com/index response: html page. After user hits submit button or another button or link, browser requests another page again. request: http://example.com/login response: another page. In another word, Jsf or any Ui framework holds information between 2 requests for us by various techniques and methods see this question about Initial request and postback request and Jsf lifecycle and primeFaces lifeCycle show case
last Point: session has timeout in jservlet and you can config it using web.xml and If this time pass, your session expires and gives you another session Happy Coding!

Reza
  • 51
  • 6