From: Roland Haeder Date: Sun, 10 Apr 2016 14:24:34 +0000 (+0200) Subject: also fire an event when a new product has been added, rather than calling addProduct... X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=bdbb276995058f268b54b58cb4dbdabfdc68b87b;p=pizzaservice-war.git also fire an event when a new product has been added, rather than calling addProduct() statically --- diff --git a/lib/jshop-core.jar b/lib/jshop-core.jar index 4a5a142a..9abcd778 100644 Binary files a/lib/jshop-core.jar and b/lib/jshop-core.jar differ diff --git a/src/java/org/mxchange/pizzaapplication/beans/product/PizzaAdminProductWebRequestBean.java b/src/java/org/mxchange/pizzaapplication/beans/product/PizzaAdminProductWebRequestBean.java index 8fe2033f..3d115e09 100644 --- a/src/java/org/mxchange/pizzaapplication/beans/product/PizzaAdminProductWebRequestBean.java +++ b/src/java/org/mxchange/pizzaapplication/beans/product/PizzaAdminProductWebRequestBean.java @@ -18,19 +18,22 @@ package org.mxchange.pizzaapplication.beans.product; 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 @@ -46,7 +49,13 @@ public class PizzaAdminProductWebRequestBean implements PizzaAdminProductWebRequ */ private static final long serialVersionUID = 5_819_375_183_472_871L; - /////////////////////// Properties ///////////////////// + /** + * Event for added product + */ + @Inject + @Any + private Event addedProductEvent; + /** * Available */ @@ -72,14 +81,6 @@ public class PizzaAdminProductWebRequestBean implements PizzaAdminProductWebRequ */ private String productTitle; - ////////////////////// Bean injections /////////////////////// - - /** - * Shop bean - */ - @Inject - private PizzaShopWebApplicationController shopController; - /** * Default constructor */ @@ -112,8 +113,8 @@ public class PizzaAdminProductWebRequestBean implements PizzaAdminProductWebRequ // 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); diff --git a/src/java/org/mxchange/pizzaapplication/beans/shop/PizzaShopWebApplicationBean.java b/src/java/org/mxchange/pizzaapplication/beans/shop/PizzaShopWebApplicationBean.java index 4992bfeb..1fbe8458 100644 --- a/src/java/org/mxchange/pizzaapplication/beans/shop/PizzaShopWebApplicationBean.java +++ b/src/java/org/mxchange/pizzaapplication/beans/shop/PizzaShopWebApplicationBean.java @@ -29,6 +29,7 @@ import javax.naming.Context; 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; @@ -79,6 +80,12 @@ public class PizzaShopWebApplicationBean implements PizzaShopWebApplicationContr this.addCategory(event.getAddedCategory()); } + @Override + public void afterShopProductAdded (@Observes final AddedProductEvent event) { + // Add it here, too. + this.addProduct(event.getAddedProduct()); + } + @Override public List getAllCategories () throws FacesException { // Return it diff --git a/src/java/org/mxchange/pizzaapplication/beans/shop/PizzaShopWebApplicationController.java b/src/java/org/mxchange/pizzaapplication/beans/shop/PizzaShopWebApplicationController.java index 992d5dc7..74b43691 100644 --- a/src/java/org/mxchange/pizzaapplication/beans/shop/PizzaShopWebApplicationController.java +++ b/src/java/org/mxchange/pizzaapplication/beans/shop/PizzaShopWebApplicationController.java @@ -20,6 +20,7 @@ import java.io.Serializable; 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; @@ -82,4 +83,13 @@ public interface PizzaShopWebApplicationController extends Serializable { * @todo Move this to own controller */ void afterShopCategoryAdded (final AddedCategoryEvent event); + + /** + * Observes events fired after a new product has been added + *

+ * @param event Event to be observed + * @todo Move this to own controller + */ + void afterShopProductAdded (final AddedProductEvent event); + }