Note that there are some explanatory texts on larger screens.

plurals
  1. POCreating session explicitly in requestScoped bean in JSF 2
    primarykey
    data
    text
    <p>I have a doubt here about creating session in requestScoped bean in JSF 2.x. I understand that we need not create session in JSF 2.x since we can directly use a sessionScoped bean to put the user required data. But I recently was introduced to a JSF code where the developer had created instance variable of session and get session from facescontext, like below</p> <pre><code> @ManagedBean @RequestScoped Public class someClass(){ FacesContext facesContext = FacesContext.getCurrentInstance(); HttpSession session = (HttpSession) facesContext.getExternalContext().getSession(true); public void someFunction(){ //Some code here.. session.setAttribute("key","value"); //Some code here.. } //rest of the code here... } </code></pre> <p>Well, I told them that one should not have "session" as a instance variable and also there is no need to get a session explicitly in JSF 2 and rather use a sessionScoped bean.</p> <p>For the first I gave a reason as "keeping session as instance variable is not thread safe" and for the second statement I gave as "you are doing a workaround for JSF session which is already provided".</p> <p>The counter-argument what I got was, For first reason "Ours is web application so there is no question of multi-threading". For second I got "Anyway the session variable will be cleared once the request is processed, so there is nothing <strong>wrong</strong> here.</p> <p>I had a no other strong points to rectify it.So my question is, 1) were they correct? 2) is there any other specific reason why we should be doing in a way it ought to be done? 3) And finally, anything which might have prompted them to use that way?</p> <p>can anybody please elaborate? Please correct me. Thanks</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload