import java.util.List;
import javax.enterprise.context.RequestScoped;
+import javax.enterprise.event.Event;
+import javax.enterprise.inject.Any;
import javax.faces.view.facelets.FaceletException;
import javax.inject.Inject;
import javax.inject.Named;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
+import org.mxchange.jshopcore.events.product.AddedProductEvent;
+import org.mxchange.jshopcore.events.product.ShopProductAddedEvent;
import org.mxchange.jshopcore.exceptions.CannotAddProductException;
import org.mxchange.jshopcore.exceptions.ProductTitleAlreadyUsedException;
import org.mxchange.jshopcore.model.category.Category;
import org.mxchange.jshopcore.model.product.AdminProductSessionBeanRemote;
import org.mxchange.jshopcore.model.product.GenericProduct;
import org.mxchange.jshopcore.model.product.Product;
-import org.mxchange.pizzaapplication.beans.shop.PizzaShopWebApplicationController;
/**
* Main application class
*/
private static final long serialVersionUID = 5_819_375_183_472_871L;
- /////////////////////// Properties /////////////////////
+ /**
+ * Event for added product
+ */
+ @Inject
+ @Any
+ private Event<AddedProductEvent> addedProductEvent;
+
/**
* Available
*/
*/
private String productTitle;
- ////////////////////// Bean injections ///////////////////////
-
- /**
- * Shop bean
- */
- @Inject
- private PizzaShopWebApplicationController shopController;
-
/**
* Default constructor
*/
// Call bean
Product updatedProduct = this.productRemoteBean.doAdminAddProduct(product);
- // Add to shop controller
- this.shopController.addProduct(updatedProduct);
+ // Fire event
+ this.addedProductEvent.fire(new ShopProductAddedEvent(updatedProduct));
// Set all to null
this.setProductAvailability(Boolean.FALSE);
import javax.naming.InitialContext;
import javax.naming.NamingException;
import org.mxchange.jshopcore.events.category.AddedCategoryEvent;
+import org.mxchange.jshopcore.events.product.AddedProductEvent;
import org.mxchange.jshopcore.model.category.Category;
import org.mxchange.jshopcore.model.category.CategorySessionBeanRemote;
import org.mxchange.jshopcore.model.product.Product;
this.addCategory(event.getAddedCategory());
}
+ @Override
+ public void afterShopProductAdded (@Observes final AddedProductEvent event) {
+ // Add it here, too.
+ this.addProduct(event.getAddedProduct());
+ }
+
@Override
public List<Category> getAllCategories () throws FacesException {
// Return it
import java.util.List;
import javax.faces.view.facelets.FaceletException;
import org.mxchange.jshopcore.events.category.AddedCategoryEvent;
+import org.mxchange.jshopcore.events.product.AddedProductEvent;
import org.mxchange.jshopcore.model.category.Category;
import org.mxchange.jshopcore.model.product.Product;
* @todo Move this to own controller
*/
void afterShopCategoryAdded (final AddedCategoryEvent event);
+
+ /**
+ * Observes events fired after a new product has been added
+ * <p>
+ * @param event Event to be observed
+ * @todo Move this to own controller
+ */
+ void afterShopProductAdded (final AddedProductEvent event);
+
}