0

I have two beans:

@Named
@SessionScoped
public class Session implements Serializable {
    private String temp;
    +getter, setter

}

@Named
@RequestScoped
public class Test {
    @Inject
    private Session s;

    @PostConstruct
    public void init() {
        this.sth = s.getTemp(); //here is exception
    }
}

When I try to fetch in init same value from session I get NullPointerException. What am I doing wrong? Server is JBoss eap 6.0, JSF v2.1. Thanks in advance

Edit: I investigated that problem appears only when I have more than 11 items in primefaces submenu component. If I have less than 11 items every thinks work OK. I am using PrimeFaces v 3.5. Edit 2: On session bean only constructor is invoked. I have method annotated with PostConstruct but it is not called. I always get NullPointerException after invoking any method on session from Test bean.

BenMorel
  • 34,448
  • 50
  • 182
  • 322
John
  • 1,350
  • 5
  • 27
  • 49
  • 5
    Are you sure that you are not using `RequestScoped` and `SessionScoped` from `javax.faces.bean` package? If you are, replace them with those from `javax.enterprise.context` package. – partlov Mar 14 '13 at 13:47
  • I just checked and in both cases I use javax.enterprise.context – John Mar 14 '13 at 13:56
  • I must ask one more thing. As `Session` is very often used name for class and it exists in many packages, are you sure that `Session` class is that you created, not imported from, for example `javax.mail` or something else? – partlov Mar 14 '13 at 14:00
  • Yes I am 100% sure that imports are correct – John Mar 14 '13 at 14:03
  • Do you get the same problem if you call `s.getTemp()` outside of the `@PostConstruct` method? – phoenix7360 Mar 15 '13 at 09:02
  • Yes it is working. Even if I come to this page that bean test is used from link it is working. It seems it is not working when I type directly address in web browser. – John Mar 15 '13 at 10:02
  • I think it is primefaces issue because I get null exception only when in submenu items length is greater than 11. If number of items in submenu is less than 11 it works perfectly fine. – John Mar 15 '13 at 10:07
  • Could you post the relevant JSF / Primefaces code? – rdcrng Mar 19 '13 at 17:32

0 Answers0