I'm using JSF in my project and i have 2 beans marked with @Component and @Scope annotations. My problem is i want to share a value between beans but it doesn't work. I mean when i set a value in first bean i want to read that value in second bean but when i try it, it throws Null pointer exception even i use ManagedBeans and managedProperty. I'm too exhausted and still struggling with this problem but i can't fix it. I can't share my code because of privacy issues but i need help. Thanks.
This is my first bean:
import javax.annotation.ManagedBean;
import javax.faces.bean.ManagedProperty;
import javax.faces.bean.SessionScoped;
@Getter
@Setter
@Component("firstBean")
@Scope("view")
@ManagedBean(value = "firstBean")
@SessionScope
public class FirstBean{
private String name;
}
when i set name in firstBean i want to read that value in second bean like (firstBean.name) but it throws NPE
import javax.annotation.ManagedBean;
import javax.faces.bean.ManagedProperty;
import javax.faces.bean.SessionScoped;
@Getter
@Setter
@Component("secondBean")
@Scope("view")
@ManagedBean(value = "secondBean")
@SessionScope
public class SecondBean{
@ManagedProperty(value = "#{firstBean}")
private FirstBean firstBean;
}