0

Using @Named("XYZ") and @SessionScoped before the Class declartion, the Session Bean is created but these beans are not stored in Session Map.

Session Map is checked as

final FacesContext context = FacesContext.getCurrentInstance(); Object obj context.getExternalContext().getSessionMap().get("XYZ");

When I put a JSF managed session bean in faces-config.xml like this

  <managed-bean>
    <managed-bean-name>XYZ</managed-bean-name>
    <managed-bean-class>blah.blah.XYZ</managed-bean-class>
    <managed-bean-scope>session</managed-bean-scope>
  </managed-bean>

I can find it session map fine.

It seems CDI beans are not stored in Session Map.

Note bean.xml exist in my project.

Kukeltje
  • 12,223
  • 4
  • 24
  • 47
  • Did this work with a previous version of Tomcat? And why are you trying to retrieve the bean this way any way? – Kukeltje Feb 04 '20 at 16:26
  • I was not using CDI earlier. I just upgraded my project to latest JSF when I came across this problem. – Pratap Tripathy Feb 04 '20 at 16:42
  • See also https://stackoverflow.com/questions/26514456/removing-beans-from-session – Kukeltje Feb 04 '20 at 16:43
  • Article "Session scoped managed bean not available as session attribute in filter – Kukeltje " does not answer my question. I use session bean to store user specific information. I use Utility method JSFUTIL.getbean(???) to get the session bean. – Pratap Tripathy Feb 04 '20 at 16:44
  • 1
    It sort of 'does' answer it since it suggests to use `@Inject` to get the bean. If the pure retrieving is not your issue but you need to do something with it that you cannot if you had it injected, you should have stated that in the question since it is an important part. The second link I posted has additional information if you need to do something with it. – Kukeltje Feb 04 '20 at 16:46
  • Off-topic:If you stil have your own `JSFUtil`, you should drop that in favour of OmniFaces. – Kukeltje Feb 04 '20 at 16:47
  • _"I use session bean to store user specific information. I use Utility method JSFUTIL.getbean(???) to get the session bean"_ I do to, but I never had the need for a JSFUtil class for this the last 8 years. You most likely have room for optimization there. – Kukeltje Feb 04 '20 at 16:49
  • JSFUtil is just helper class. I have got code like this 'code' public static Object getBean(final String expr) { final FacesContext context = FacesContext.getCurrentInstance(); if (context == null) { return null; } return context.getExternalContext().getSessionMap().get(expr); } Nothing special about it. – Pratap Tripathy Feb 05 '20 at 05:00
  • 1
    Onhe contrary, a lot is special about this. WHY do you read a bean from the sessionmap like that. I never did this. See the other link I posted... – Kukeltje Feb 05 '20 at 06:24

0 Answers0