*/
package org.mxchange.pizzaapplication.beans.product;
+import java.util.Collections;
import java.util.List;
+import javax.annotation.PostConstruct;
import javax.enterprise.context.RequestScoped;
import javax.enterprise.event.Event;
import javax.enterprise.inject.Any;
*/
private String productTitle;
+ /**
+ * Cache for all products
+ */
+ private List<Product> products;
+
/**
* Default constructor
*/
// Call bean
Product updatedProduct = this.productRemoteBean.doAdminAddProduct(product);
+ // Add updated product to local list
+ this.products.add(updatedProduct);
+
// Fire event
this.addedProductEvent.fire(new ShopProductAddedEvent(updatedProduct));
@Override
public List<Product> getAllProducts () throws FaceletException {
// Call bean
- return this.productRemoteBean.getAllProducts();
+ return Collections.unmodifiableList(this.products);
}
@Override
this.productTitle = productTitle;
}
+ /**
+ * Initializer method
+ */
+ @PostConstruct
+ public void init () {
+ // Initialize list
+ this.products = this.productRemoteBean.getAllProducts();
+ }
+
/**
* Clears this bean (example: product has been added)
*/