I'm confronted with the problem of passing a value from a bean to another bean via injection.
The program structure: A user searches for pizzas, the program generates PizzaObjects and add it to the list 'results'. Now I want to pass the list to the bean PizzaResult.
my ManagedBean looks like this:
@ManagedBean
@SessionScoped
public class PizzaSearch {
// variables
private List<PizzaObject> results = new ArrayList<PizzaObject>();
// methods to search for different pizzas
// methods to fill the list of PizzaObjects
// getter - setter
public List<PizzaObject> getResults() {
return results;
}
Code snippet of the other bean:
@ManagedBean
@SessionScoped
public class PizzaResult {
// injection
@ManagedProperty(value="#{pizzaSearch}")
private PizzaSearch pizzaSearch;
// variables
private List<PizzaObject> results;
@PostConstruct
public void initResults() {
results = pizzaSearch.getResults(); // results = empty
int size = results.size(); // size = 0
this._chosenSize = new int[size]; // chosenSize = 0
this._chosenQuantity = new int[size]; // chosenQuantity = 0
}
public void addToCart(int index) {
System.out.println("Parameter: " + results.get(index).getPizza().getPizzaID());
System.out.println("chosen size: " + getChosenSize()[index]);
System.out.println("chosen quantity: " + getChosenQuantity()[index]);
}
// getter and setter
I need to initialize the results in the PostConstruct but somehow each value is 0 there..