I have this scenario:
I've got a goToDetail(String item)
method in loginBean
that should lead to page2.xhtml when item is selected.
When I try to pass properties from loginBean
to dettaglioBean
, properties are null
in dettaglioBean
when page2.xhtml is rendered or @PostConstruct
is raised.
Here is the goToDetail
method:
public String goToDetail(VStatoavanzamentoriep item) {
FacesContext context = FacesContext.getCurrentInstance();
DettaglioBean bean = (DettaglioBean) context.getApplication().evaluateExpressionGet(context, "#{dettaglioBean}", DettaglioBean.class);
bean.setItem(item);
return Constants.PageID.DettaglioID;
}
and dettaglioBean
is declared as managedBean
in faces-config.xml
When I go to page2.xhtml, item
is null
.
Should I use dependency injection including:
@ManagedProperty("#{dettaglioBean}") //+ setter
private DettaglioBean dettaglioBean;
in loginBean
?
You can access the values in loginBean by injecting the loginBean into dettaglioBean and not the other way round, since it is the values in loginBean that you need in dettaglioBean.
@ManagedProperty("#{loginBean}")
private LoginBean loginBean;
When the JSF implementation comes across the EL, it searches for the bean object in the various scope maps and when it finds it, injects it into your dettaglioBean.