From 3b1f76fed100ca994989f075adbf92bd2fb9be24 Mon Sep 17 00:00:00 2001 From: Roland Haeder Date: Sun, 10 Apr 2016 15:56:50 +0200 Subject: [PATCH] Continued a bit: - replaced "static add-call" to event-based approach. This is much more flexible and easier to expand - updated jar(s) --- lib/jcoreee.jar | Bin 19091 -> 19091 bytes lib/jshop-core.jar | Bin 46036 -> 48594 bytes .../basket/PizzaBasketWebSessionBean.java | 13 +++++++++- .../PizzaAdminCategoryWebRequestBean.java | 24 ++++++++++-------- .../shop/PizzaShopWebApplicationBean.java | 9 ++++++- .../PizzaShopWebApplicationController.java | 11 ++++++++ 6 files changed, 44 insertions(+), 13 deletions(-) diff --git a/lib/jcoreee.jar b/lib/jcoreee.jar index 3a32dfff27965a3b537e31aae5fea9bcc5de3288..ad61871dc3c447ae7b78f28e4fee6bf4892cb44f 100644 GIT binary patch delta 347 zcmbO{m2vV^MxFp~W)?061`Y-W=DLYInoLY}6U`TZ$eRiv@;69ivKpfyh>B#i0#Q>L ztwGc!Mh6hJg2`}lf->vmJ`a9wxLH8)A3*W>YV4EeFmXYY`GKe(Oim!mhS>v1ZEj<( zVF%GH+~yo0+E%!f2Sjg?pT`QKLsXr(LG%oRC@}wv={>OeE4FE@Ow2%IoGpRUlgpjK zF4^g90OGxd2&%a_f_RxOULb0#i#Ld3at#1c9Bwj`3tYi2$pA7hxSByk<3Ln~TM&ra s;}!v;#M~1=RE2vAh`Q&V1){t>8bQ=qk4z9{;aLu%HhN}*C^@fE09Z0(hX4Qo delta 347 zcmbO{m2vV^MxFp~W)?061`Y;>SveDVG?`}ROf+8rB5x{y$loB5$!d&-AS#m43Peq1 zv<6X^7#%>=3MRwJ3CgUK`#ku$;bsBFe*nejtFcd>!^8zq<_DsFFgbxJ8)gq6wYiPC zh8;w+aGP_0Xj|b@9uU1nejY1`4pDXD2GKJNqQLwwruV?=uh^!sGR*=S<7^3(o?Pw> zcF9g>0}$^uL{QDe5yZ=M@d8m>UA#dQlWPEo;&79hT;K|J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}Be*cq!|R-~elf;{B;rntZb1NoYFNdBzmppptZ|1wvRiN_D~Unb@slQY?!n)zzDN1|~8f5+|=VY>$h1^XGh zM*x-D3~mp9)yJ52^u>VHrG+0JF&-P$dG+5P3xr@41R5pecI_u-?o0%W$p{6#5ty{J zSE70?XCH(wnPXotcCT)h4FN->VNS{Flc-PRO5LKR(A>wfbTPKsz*rL;U1CI*7t;G~ z&%ruM2u8M|kg7=Dovk_=PCw)+>K;mT$KqKw7~de)_Az7_qYEBMQQ@|ghg_i^JL%PlnAKiLFFqEx-wlcFBItn6TjhEM3MySDr27lBV94W$_D05 zf#F6?!2E5q^rV~(8zVzuHny-Qad8(z@sON(U#*y3%ytE1rNaE`7B{yHC54)Zi4-m% J list = this.basket.getAll(); // Debug message //this.getLogger().logDebug(MessageFormat.format("getItemFromProduct: list={0}", list)); + // Check all entries for (final AddableBasketItem item : list) { // Debug message @@ -477,6 +487,7 @@ public class PizzaBasketWebSessionBean implements PizzaBasketWebSessionControlle // Trace message //this.getLogger().logTrace(MessageFormat.format("getItemFromProduct: foundItem={0} - EXIT!", foundItem)); + // Return it return foundItem; } diff --git a/src/java/org/mxchange/pizzaapplication/beans/category/PizzaAdminCategoryWebRequestBean.java b/src/java/org/mxchange/pizzaapplication/beans/category/PizzaAdminCategoryWebRequestBean.java index e1a067bc..35df9066 100644 --- a/src/java/org/mxchange/pizzaapplication/beans/category/PizzaAdminCategoryWebRequestBean.java +++ b/src/java/org/mxchange/pizzaapplication/beans/category/PizzaAdminCategoryWebRequestBean.java @@ -17,18 +17,21 @@ package org.mxchange.pizzaapplication.beans.category; 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.category.AddedCategoryEvent; +import org.mxchange.jshopcore.events.category.ShopCategoryAddedEvent; import org.mxchange.jshopcore.exceptions.CannotAddCategoryException; import org.mxchange.jshopcore.exceptions.CategoryTitleAlreadyUsedException; import org.mxchange.jshopcore.model.category.AdminCategorySessionBeanRemote; import org.mxchange.jshopcore.model.category.Category; import org.mxchange.jshopcore.model.category.ProductCategory; -import org.mxchange.pizzaapplication.beans.shop.PizzaShopWebApplicationController; /** * Main application class @@ -44,6 +47,13 @@ public class PizzaAdminCategoryWebRequestBean implements PizzaAdminCategoryWebRe */ private static final long serialVersionUID = 5_819_375_183_472_871L; + /** + * Event for added shop categories + */ + @Inject + @Any + private Event categoryAddedEvent; + /** * Remote bean for categories */ @@ -60,14 +70,6 @@ public class PizzaAdminCategoryWebRequestBean implements PizzaAdminCategoryWebRe */ private Category parentCategory; - ////////////////////// Bean injections /////////////////////// - - /** - * Shop bean - */ - @Inject - private PizzaShopWebApplicationController shopController; - /** * Default constructor */ @@ -96,8 +98,8 @@ public class PizzaAdminCategoryWebRequestBean implements PizzaAdminCategoryWebRe // Deligate to remote bean Category updatedCategory = this.categoryBean.doAdminAddCategory(category); - // Also send it to the controller bean - this.shopController.addCategory(updatedCategory); + // Fire event + this.categoryAddedEvent.fire(new ShopCategoryAddedEvent(updatedCategory)); // Unset all older values this.setCategoryTitle(""); //NOI18N diff --git a/src/java/org/mxchange/pizzaapplication/beans/shop/PizzaShopWebApplicationBean.java b/src/java/org/mxchange/pizzaapplication/beans/shop/PizzaShopWebApplicationBean.java index 29dbdfb2..4992bfeb 100644 --- a/src/java/org/mxchange/pizzaapplication/beans/shop/PizzaShopWebApplicationBean.java +++ b/src/java/org/mxchange/pizzaapplication/beans/shop/PizzaShopWebApplicationBean.java @@ -21,12 +21,14 @@ import java.util.LinkedList; import java.util.List; import javax.annotation.PostConstruct; import javax.enterprise.context.ApplicationScoped; +import javax.enterprise.event.Observes; import javax.faces.FacesException; import javax.faces.view.facelets.FaceletException; import javax.inject.Named; import javax.naming.Context; import javax.naming.InitialContext; import javax.naming.NamingException; +import org.mxchange.jshopcore.events.category.AddedCategoryEvent; import org.mxchange.jshopcore.model.category.Category; import org.mxchange.jshopcore.model.category.CategorySessionBeanRemote; import org.mxchange.jshopcore.model.product.Product; @@ -71,6 +73,12 @@ public class PizzaShopWebApplicationBean implements PizzaShopWebApplicationContr } } + @Override + public void afterShopCategoryAdded (@Observes final AddedCategoryEvent event) { + // Add it here, too. + this.addCategory(event.getAddedCategory()); + } + @Override public List getAllCategories () throws FacesException { // Return it @@ -90,7 +98,6 @@ public class PizzaShopWebApplicationBean implements PizzaShopWebApplicationContr @Override public List getAvailableProducts () throws FacesException { // Return it - // TODO Find something better here to prevent warning return Collections.unmodifiableList(this.availableProducts); } diff --git a/src/java/org/mxchange/pizzaapplication/beans/shop/PizzaShopWebApplicationController.java b/src/java/org/mxchange/pizzaapplication/beans/shop/PizzaShopWebApplicationController.java index b7ccb5c8..992d5dc7 100644 --- a/src/java/org/mxchange/pizzaapplication/beans/shop/PizzaShopWebApplicationController.java +++ b/src/java/org/mxchange/pizzaapplication/beans/shop/PizzaShopWebApplicationController.java @@ -19,6 +19,7 @@ package org.mxchange.pizzaapplication.beans.shop; 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.model.category.Category; import org.mxchange.jshopcore.model.product.Product; @@ -33,6 +34,7 @@ public interface PizzaShopWebApplicationController extends Serializable { * Adds given category to the "cached" instance *

* @param category Category instance + * @todo Move this to own controller */ void addCategory (final Category category); @@ -49,6 +51,7 @@ public interface PizzaShopWebApplicationController extends Serializable { * @return All categories *

* @throws javax.faces.view.facelets.FaceletException If anything went wrong + * @todo Move this to own controller */ List getAllCategories () throws FaceletException; @@ -59,6 +62,7 @@ public interface PizzaShopWebApplicationController extends Serializable { * @return All categories *

* @throws javax.faces.view.facelets.FaceletException If anything went wrong + * @todo Move this to own controller */ List getAllCategoriesParent () throws FaceletException; @@ -71,4 +75,11 @@ public interface PizzaShopWebApplicationController extends Serializable { */ List getAvailableProducts () throws FaceletException; + /** + * Observes events fired after a new product category has been added + *

+ * @param event Event to be observed + * @todo Move this to own controller + */ + void afterShopCategoryAdded (final AddedCategoryEvent event); } -- 2.39.5