ello
I have 2 Managed beans, one View scoped, the other Session scoped. The View scoped bean is defined as
@ManagedBean
@ViewScoped
public class InvoiceController implements Serializable {
private static final long serialVersionUID = 1L;
@ManagedProperty(value="#{invoiceService}")
private InvoiceService invoiceService;
The session scoped bean as
@ManagedBean
@SessionScoped
public class InvoiceService implements Serializable{
I am using the session scoped bean to hold a flag used to decide if a panel should be rendered, when I run this through the debug I find that every time I call the method on the sesison bean, it is a new instance of the bean and therefore does not retain the value of my flag between requests.
What am I doing wrong?
That can happen if you have imported @SessionScoped from the javax.enterprise.context package instead of from the javax.faces.bean package. The former works on CDI @Named beans only, while the latter works on JSF @ManagedBean beans only.
A JSF @ManagedBean without any valid scope would default to @NoneScoped which means that it's newly constructed on every single EL expression referencing the bean, such as the @ManagedProperty. This explains the symptoms you're seeing.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With