I can't pass values between two managed beans of different pages. I am implementing a search box JSF component in a Home page. I request some values and when the user hits search it goes to the search result page. The search result page has a JSF component SEARCH RESUKTS which needs to access the selection in the managed bean which correspond to the search box from the home page.
I have tried using injection but it seams that the Managed BEan box is reintialized, showing the default value. I pick an interest from the search box, i.e. Cinema, then I click search which takes me to search result, I hope to see cinema but I see Sport the defualt value. Please find the code below.
SEARCH RESULT MANAGED BEAN
import javax.el.ELContext;
import javax.faces.bean.ApplicationScoped;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ManagedProperty;
import javax.faces.bean.RequestScoped;
import javax.faces.context.FacesContext;
@ManagedBean
@ApplicationScoped
public class ExpSearchResultsMB {
/** Creates a new instance of ExpSearchResultsMB */
public ExpSearchResultsMB() {
}
@ManagedProperty(value="#{expSearchBoxMB.selectedValue}")
private String selectedValue; // +setter
@ManagedProperty(value="#{expSearchBoxMB.text}")
private String prova;
public String getProva() {
return prova;
}
public void setProva(String prova) {
this.prova = prova;
}
public String getSelectedValue() {
return selectedValue;
}
public void setSelectedValue(String selectedValue) {
this.selectedValue = selectedValue;
}
}
SEARCH BOX MANAGED BEAN
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
import javax.faces.bean.ApplicationScoped;
import javax.faces.bean.ManagedProperty;
@ManagedBean
@ApplicationScoped
public class ExpSearchBoxMB {
public Date date;
public List<String> interests=new ArrayList<String>();
public String selectedValue="Sport";
public String getSelectedValue() {
return selectedValue;
}
public void setSelectedValue(String selectedValue) {
this.selectedValue = selectedValue;
}
public List<String> getInterests() {
interests.add("Sport");
interests.add("Musin");
interests.add("Art");
interests.add("Thatre");
interests.add("Cinema");
return interests;
}
public void setInterests(List<String> interests) {
this.interests = interests;
}
I would appreciate any help.
Cheers