Passing session between jsf backing bean and model

Posted by Rachel on Stack Overflow See other posts from Stack Overflow or by Rachel
Published on 2012-06-26T13:58:56Z Indexed on 2012/07/03 15:16 UTC
Read the original article Hit count: 215

Filed under:
|
|
  • Background :

I am having backing bean which has upload method that listen when file is uploaded. Now I pass this file to parser and in parser am doing validation check for row present in csv file.

If validation fails, I have to log information and saving in logging table in database.

  • My end goal :

Is to get session information in logging bean so that I can get initialContext and make call to ejb to save data to database.

  • What is happening :

In my upload backing bean, am getting session but when i call parser, I do not pass session information as I do not want parser to be dependent on session as I want to unit test parser individually.

So in my parser, I do not have session information, from parser am making call to logging bean(just a bean with some ejb methods) but in this logging bean, i need session because i need to get initial context.

Question

  1. Is there a way in JSF, that I can get the session in my logging bean that I have in my upload backing bean?

I tried doing:

FacesContext ctx = FacesContext.getCurrentInstance();
HttpSession session = (HttpSession) ctx.getExternalContext().getSession(false);

but session value was null, more generic question would be :

  1. How can I get session information in model bean or other beans that are referenced from backing beans in which we have session?
  2. Do we have generic method in jsf using which we can access session information throughout JSF Application?

© Stack Overflow or respective owner

Related posts about java

Related posts about session