Domanda

I have this scenario:

  1. page1.xhtml managed by loginBean.java
  2. page2.xhtml managed by dettaglioBean.java

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?

È stato utile?

Soluzione

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.

Altri suggerimenti

There are methods to send or set data in managed beans. Please read the BalusC answer.

Related Post

https://stackoverflow.com/a/4994833/892994

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top