]> git.mxchange.org Git - pizzaservice-war.git/commitdiff
also fire an event when a new product has been added, rather than calling addProduct...
authorRoland Haeder <roland@mxchange.org>
Sun, 10 Apr 2016 14:24:34 +0000 (16:24 +0200)
committerRoland Haeder <roland@mxchange.org>
Sun, 10 Apr 2016 14:24:34 +0000 (16:24 +0200)
lib/jshop-core.jar
src/java/org/mxchange/pizzaapplication/beans/product/PizzaAdminProductWebRequestBean.java
src/java/org/mxchange/pizzaapplication/beans/shop/PizzaShopWebApplicationBean.java
src/java/org/mxchange/pizzaapplication/beans/shop/PizzaShopWebApplicationController.java

index 4a5a142ab616548f87024661db78d6cf318311fd..9abcd77805e3afa5dee6aff49114f03c5c505c53 100644 (file)
Binary files a/lib/jshop-core.jar and b/lib/jshop-core.jar differ
index 8fe2033f89f3dac98d1f74c8edf8b2225d924cd4..3d115e0945612a0d918a0ee6732a5879c7b48954 100644 (file)
@@ -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> 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);
index 4992bfeb84086ff0cd020510ecc7488ea31f81c4..1fbe8458c1ac8971bda1df83fd9a4a05edf1488a 100644 (file)
@@ -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<Category> getAllCategories () throws FacesException {
                // Return it
index 992d5dc746909d30723b43c9f10ab178e8e8a333..74b43691618472e95c721edeb807d437cada1aca 100644 (file)
@@ -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
+        * <p>
+        * @param event Event to be observed
+        * @todo Move this to own controller
+        */
+       void afterShopProductAdded (final AddedProductEvent event);
+
 }