From 02830017bb45e6a89e10d39b641e49e390f97e63 Mon Sep 17 00:00:00 2001 From: Roland Haeder Date: Fri, 11 Sep 2015 15:40:09 +0200 Subject: [PATCH] =?utf8?q?Continued=20with=20fixing:=20-=20add=20validator?= =?utf8?q?=20for=20amount=20-=20some=20beans=20now=20have=20"cache"=20to?= =?utf8?q?=20save=20EJB=20calls=20and=20notify=20"controller"=20bean=20-?= =?utf8?q?=20the=20gender=20bean=20does=20not=20need=20to=20get=20the=20ge?= =?utf8?q?nders=20from=20an=20EJB=20(saves=20a=20lot=20bandwidth)=20-=20ne?= =?utf8?q?wly=20thrown=20exceptions=20added=20-=20updated=20jars=20Signed-?= =?utf8?q?off-by:Roland=20H=C3=A4der=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- lib/jcoreee.jar | Bin 13934 -> 18417 bytes lib/jshop-core.jar | Bin 25508 -> 26951 bytes lib/jshop-ee-lib.jar | Bin 7225 -> 6829 bytes .../localization/bundle_de_DE.properties | 4 +- .../localization/bundle_en_US.properties | 6 +- .../beans/basket/BasketWebBean.java | 188 +++++++++++++----- .../beans/basket/BasketWebController.java | 14 ++ .../beans/category/AdminCategoryWebBean.java | 15 +- .../beans/controller/ShopWebBean.java | 99 +++++---- .../beans/controller/ShopWebController.java | 14 ++ .../beans/gender/GenderWebBean.java | 31 +-- .../beans/product/AdminProductWebBean.java | 16 +- web/WEB-INF/faces-config.xml | 6 +- web/WEB-INF/glassfish-web.xml | 14 +- web/WEB-INF/templates/basket/mini_basket.tpl | 8 +- web/WEB-INF/templates/guest/guest_base.tpl | 8 +- web/WEB-INF/tlds/basket.tld | 4 +- web/index.xhtml | 156 +++++---------- 18 files changed, 316 insertions(+), 267 deletions(-) diff --git a/lib/jcoreee.jar b/lib/jcoreee.jar index b2760ebae295cbad0437e4e512da91af8eca0b2c..893d1f9aad9b8ec2bf4607d123795b6547d7a940 100644 GIT binary patch delta 4659 zcma)Adr(}}8UNjV-QBx)fh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yk2orTihJ11l#F@VQqP#9KV07YUbm8fLLxfocmlDHsi02`e=5+ t-1V~yVfFYilfB`$Q(w_VpO-y9u;=H8DjqkbA9K0tS*d(NQJj#fe*>}FY777X diff --git a/lib/jshop-ee-lib.jar b/lib/jshop-ee-lib.jar index ff8228177692e04aa42d48e83eaee3ff342a43c8..34f03eac5266bc772c35170ff88b0f27a631a267 100644 GIT binary patch delta 936 zcmZvaO-NKx6vxlKZ^k>mdGkKzYZu)!He*vgxbJsA{^yPgE zs7%e zi|VzHNe+XX4BH@ z)m(lae^_>ec^G)W3k+&xQXeQFz=!v}N95Hv7yJ)7u|c0^#9PJ(9w3un&$|9K>0k{n z2glXuentUd+zMXuLxw{la~*zTr9%I+uJ zu}2A?>9+i= zFTe2Ot~ZT2M=J>r$_X%BR!OcehXgLi8f9Dh@UD6Y-MU~YV8`q#_R7CcqrWQPL2V`A zQC)LMyn9p8xNKP()#9`!#YZtw-%J-9u8;GLfHc;CPfQ=WR-%%xQf-+pU6pU%{2gGR N7Eh{i0dONkieHxGV;KoDbd!39d*m#`DrsR5xjKeMF3fO? zYob`-L-^VyihH3K_!ygR;iLA=SZ!N*UB3Dw0bs2aa9(!elG}$wUxDBFjUr#0nn~iC zl)yP%B~BS5xTQDYY*E{*g7$&j^>6&GFbsi>B^yO>+oo9k^t`yB(yPIs3!MC zQvMT(dg@bZE}Bjgu=xX>*OVJda6C7Z4t6P{5dwz(p;Si6jgP4W693Mh*>+DWnN+ZI zB$JBZysez=x$3aeIT}o$N}WnJMO%JiEt-`$leNwL`_RM*of{5XD~3 zjg1DQymuwh^q8t7Cuu13Sv^FLM#*~_bo83Q2#gY#fQAJC4lHzR1)FBKgF~~)TJHoG zrJj1a0rtPF+P3zW?{%MPwpnWjTy*(ys<<2%C5vbmz$AcK01M6u37u5{+wzuhlHebs zi4Z*QkdIPTgQlSEM^lgvDl9)WJmKgQTRtxh62=wN8fRk9rR!(@?EnWbfDf(xqLW4! zfJ!>>yY&*0@rXHqk40(uw(Y8>h#`j=J(BZ;c4`AX3oQ?-Z=}tneVM_sb4n}Q1L0)8 zP(e8B2-6b6RR=2r)XO1;23f0(tlY>(D{?EtZ@G)1-Fbmw(b>%K)fs09xq2AxxcV4A zY@^2AYdcgs_`uzSGbJ8u^oo@Sivu7^w^{h*XPy_Km1iXp(i{&aq~HdSpQ$$Nrl+#R z&UUcj@o^cWW-a&DGE0Zo$I*MT@_xK8Rp63WV%AsGI$_adzL<+~+ERuzf+n|{1)7QG YJvAy9x9=>l;B-lqSSrweBPa9t3q_GE7ytkO diff --git a/src/java/org/mxchange/localization/bundle_de_DE.properties b/src/java/org/mxchange/localization/bundle_de_DE.properties index ef91ec23..97e888d7 100644 --- a/src/java/org/mxchange/localization/bundle_de_DE.properties +++ b/src/java/org/mxchange/localization/bundle_de_DE.properties @@ -28,4 +28,6 @@ YES=Ja NO=Nein PARENT_CATEGORY_CANNOT_BE_NULL=Elternkategorie darf nicht leer sein. CATEGORY_MUST_BE_SELECTED=Es muss eine Kategorie ausgewaehlt werden. -ITEM_AMOUNT_IS_REQUIRED=Bestellmenge wird benoetigt. +ERROR_AMOUNT_IS_NULL=Die Bestellmenge ist nicht gesetzt. +BUTTON_TITLE_ADD_ITEM_TO_BASKET=F\u00fcgt das Produkt dem Warenkorb hinzu. +INPUT_TITLE_ENTER_ITEM_AMOUNT=Geben Sie hier die Bestellmenge ein. diff --git a/src/java/org/mxchange/localization/bundle_en_US.properties b/src/java/org/mxchange/localization/bundle_en_US.properties index 9554539c..0b039d7e 100644 --- a/src/java/org/mxchange/localization/bundle_en_US.properties +++ b/src/java/org/mxchange/localization/bundle_en_US.properties @@ -18,7 +18,7 @@ GENDER_FEMALE=Mrs. GENDER_COMPANY=Company MiniBasketTag.basket_is_empty=The basket is empty. MiniBasketTag.last_item=Last added item: {0} -MiniBasketTag.additional_items=There are {0} items in the basket. +MiniBasketTag.additional_items=There are {0} items in the basketController. MiniBasketTag.to_basket=To basket MiniBasketTag.header=Basket CATEGORY_HAS_NO_PARENT=No parent category @@ -26,4 +26,6 @@ YES=Yes NO=No PARENT_CATEGORY_CANNOT_BE_NULL=Parent category cannot be empty. CATEGORY_MUST_BE_SELECTED=You have to select a category. -ITEM_AMOUNT_IS_REQUIRED=Order amount is required. +ERROR_AMOUNT_IS_NULL=Order amount is not set. +BUTTON_TITLE_ADD_ITEM_TO_BASKET=Adds the product to the basket. +INPUT_TITLE_ENTER_ITEM_AMOUNT=Enter order amount here. diff --git a/src/java/org/mxchange/pizzaapplication/beans/basket/BasketWebBean.java b/src/java/org/mxchange/pizzaapplication/beans/basket/BasketWebBean.java index e3965945..89177ad3 100644 --- a/src/java/org/mxchange/pizzaapplication/beans/basket/BasketWebBean.java +++ b/src/java/org/mxchange/pizzaapplication/beans/basket/BasketWebBean.java @@ -16,6 +16,7 @@ */ package org.mxchange.pizzaapplication.beans.basket; +import java.util.Map; import javax.annotation.PostConstruct; import javax.enterprise.context.SessionScoped; import javax.faces.FacesException; @@ -25,7 +26,9 @@ import javax.naming.NamingException; import org.mxchange.jcoreee.beans.BaseFrameworkBean; import org.mxchange.jshopcore.exceptions.BasketItemAlreadyAddedException; import org.mxchange.jshopcore.model.basket.AddableBasketItem; +import org.mxchange.jshopcore.model.basket.Basket; import org.mxchange.jshopcore.model.basket.BasketSessionBeanRemote; +import org.mxchange.jshopcore.model.basket.ShopBasket; import org.mxchange.jshopcore.model.item.BasketItem; import org.mxchange.jshopcore.model.product.Product; @@ -34,7 +37,7 @@ import org.mxchange.jshopcore.model.product.Product; * * @author Roland Haeder */ -@Named ("basket") +@Named ("basketController") @SessionScoped public class BasketWebBean extends BaseFrameworkBean implements BasketWebController { @@ -44,14 +47,19 @@ public class BasketWebBean extends BaseFrameworkBean implements BasketWebControl private static final long serialVersionUID = 5_476_347_320_198L; /** - * Basket bean + * Ordered amount */ - private final BasketSessionBeanRemote basketBean; + private Long amount; /** - * Ordered amount + * Instance of wrapped basket */ - private Long amount; + private final Basket basket; + + /** + * Basket bean + */ + private final BasketSessionBeanRemote basketBean; /** * Current item @@ -67,10 +75,45 @@ public class BasketWebBean extends BaseFrameworkBean implements BasketWebControl // Get initial context InitialContext context = new InitialContext(); + // Get new application instance + this.basket = new ShopBasket(); + // Try to lookup this.basketBean = (BasketSessionBeanRemote) context.lookup("ejb/stateless-basket"); //NOI18N } + @Override + public String addItem (final Product product) { + // Generate item instance + AddableBasketItem item = new BasketItem(product, this.getAmount()); + + // Is amount set? + if (this.getAmount() == null) { + // No amount specified?! + return null; + } + + try { + // item should not be null + if (null == item) { + // Abort here + throw new NullPointerException("item is null"); //NOI18N + } + + // Deligate to model + this.basket.addItem(item); + + // Remove amount + this.setAmount(null); + + // Added + return "item_added"; //NOI18N + } catch (final BasketItemAlreadyAddedException ex) { + // Throw unchecked exception + throw new FacesException(ex); + } + } + @Override public Float calculateItemPrice () { // Is the current item/amount set? @@ -96,31 +139,32 @@ public class BasketWebBean extends BaseFrameworkBean implements BasketWebControl public Long getAmount () { return this.amount; } - + @Override public void setAmount (final Long amount) { this.amount = amount; } @Override - public boolean isProductAdded (final Product product) { - // Must not be null - if (null == product) { - // Abort here - throw new NullPointerException("product is null"); //NOI18N - } + public AddableBasketItem getCurrentItem () { + return this.currentItem; + } - // Generate fake instance - AddableBasketItem item = new BasketItem(product); + @Override + public void setCurrentItem (final AddableBasketItem currentItem) { + this.currentItem = currentItem; + } - // Ask bean about it - return this.getBasketBean().isAdded(item); + @Override + public AddableBasketItem getLast () { + // Deligate to basket instance + return this.basket.getLast(); } @Override - public boolean isEmpty () { - // Check local "cache" - return this.getBasketBean().isEmpty(); + public int getLastNumRows () { + // Deligate to basket instance + return this.basket.getLastNumRows(); } @Override @@ -130,11 +174,44 @@ public class BasketWebBean extends BaseFrameworkBean implements BasketWebControl } @PostConstruct - public void init () throws RuntimeException { - // Call super init first + public void init () { + // Call generic init first super.genericInit(); } + @Override + public boolean isEmpty () { + // Deligate to basket instance + return this.basket.isEmpty(); + } + + @Override + public boolean isProductAdded (final Product product) { + // Must not be null + if (null == product) { + // Abort here + throw new NullPointerException("product is null"); //NOI18N + } + + // Generate fake instance + AddableBasketItem fake = new BasketItem(product); + + // Ask bean about it + boolean isAdded = this.basket.isAdded(fake); + + // Is it added? + if (isAdded) { + // Get item + AddableBasketItem item = this.getItemFromProduct(product); + + // Set this as current item + this.setCurrentItem(item); + } + + // Return status + return isAdded; + } + /** * Getter for basket bean instance * @@ -144,45 +221,50 @@ public class BasketWebBean extends BaseFrameworkBean implements BasketWebControl return this.basketBean; } - @Override - public String addItem (final Product product) { - // Generate item instance - AddableBasketItem item = new BasketItem(product); - - // Is amount set? - if (this.getAmount() == null) { - // No amount specified?! - return null; + /** + * Somewhat getter for an item instance from given product instance. This + * method returns null if no item was found to given product. The product is + * found by checking it's id and itemType=product + * + * @param product Product instance + * @return Item instance or null if not found + */ + private AddableBasketItem getItemFromProduct (final Product product) { + // Product must not be null + if (null == product) { + // Abort here + throw new NullPointerException("product is null"); //NOI18N } - // Set amount - item.setAmount(this.getAmount()); + // Create item instance + AddableBasketItem foundItem = null; - try { - // Handle it to bean - this.getBasketBean().addItem(item); + // Create fake instance + AddableBasketItem fake = new BasketItem(product); - // Add item to local basket, too - //this.basket.addItem(item); + // Get all items + Map map = this.basket.getAll(); - // Remove amount - this.setAmount(null); + // Check all entries + for (Map.Entry entrySet : map.entrySet()) { + // Get item + AddableBasketItem item = entrySet.getValue(); - // Added - return "item_added"; //NOI18N - } catch (final BasketItemAlreadyAddedException ex) { - // Throw unchecked exception - throw new FacesException(ex); - } - } + // item must not be null + if (null == item) { + // Abort here + throw new NullPointerException("item is null"); //NOI18N + } - @Override - public AddableBasketItem getCurrentItem () { - return this.currentItem; - } + // Is it the same? + if (item.equals(fake)) { + // Set found item and abort look + foundItem = item; + break; + } + } - @Override - public void setCurrentItem (final AddableBasketItem currentItem) { - this.currentItem = currentItem; + // Return it + return foundItem; } } diff --git a/src/java/org/mxchange/pizzaapplication/beans/basket/BasketWebController.java b/src/java/org/mxchange/pizzaapplication/beans/basket/BasketWebController.java index d0713506..ad81ef88 100644 --- a/src/java/org/mxchange/pizzaapplication/beans/basket/BasketWebController.java +++ b/src/java/org/mxchange/pizzaapplication/beans/basket/BasketWebController.java @@ -94,4 +94,18 @@ public interface BasketWebController extends Serializable { * @return Current item's total price */ public Float calculateItemPrice (); + + /** + * Getter for last entry + * + * @return Last added item in basket + */ + public AddableBasketItem getLast (); + + /** + * Getter for last num rows + * + * @return Last num rows + */ + public int getLastNumRows (); } diff --git a/src/java/org/mxchange/pizzaapplication/beans/category/AdminCategoryWebBean.java b/src/java/org/mxchange/pizzaapplication/beans/category/AdminCategoryWebBean.java index 2be39da7..0f73f9b4 100644 --- a/src/java/org/mxchange/pizzaapplication/beans/category/AdminCategoryWebBean.java +++ b/src/java/org/mxchange/pizzaapplication/beans/category/AdminCategoryWebBean.java @@ -18,6 +18,7 @@ package org.mxchange.pizzaapplication.beans.category; import javax.enterprise.context.RequestScoped; import javax.faces.view.facelets.FaceletException; +import javax.inject.Inject; import javax.inject.Named; import javax.naming.InitialContext; import javax.naming.NamingException; @@ -26,6 +27,7 @@ import org.mxchange.jshopcore.exceptions.CategoryTitleAlreadyUsedException; import org.mxchange.jshopcore.model.category.Category; import org.mxchange.jshopcore.model.category.CategorySessionBeanRemote; import org.mxchange.jshopcore.model.category.ProductCategory; +import org.mxchange.pizzaapplication.beans.controller.ShopWebController; /** * Main application class @@ -36,7 +38,7 @@ import org.mxchange.jshopcore.model.category.ProductCategory; @RequestScoped public class AdminCategoryWebBean extends BaseFrameworkBean implements AdminCategoryWebController { /** - * Serial id + * Serial number */ private static final long serialVersionUID = 5_819_375_183_472_871L; @@ -45,6 +47,12 @@ public class AdminCategoryWebBean extends BaseFrameworkBean implements AdminCate */ private final CategorySessionBeanRemote categoryBean; + /** + * Shop bean + */ + @Inject + private ShopWebController controller; + /** * Category title */ @@ -76,8 +84,11 @@ public class AdminCategoryWebBean extends BaseFrameworkBean implements AdminCate category.setParentId(this.getParentId()); category.setTitle(this.getTitle()); - // Deligate to bean + // Deligate to remote bean this.categoryBean.doAdminAddCategory(category); + + // Also send it to the controller bean + this.controller.addCategory(category); } catch (final CategoryTitleAlreadyUsedException ex) { // Continue to throw throw new FaceletException(ex); diff --git a/src/java/org/mxchange/pizzaapplication/beans/controller/ShopWebBean.java b/src/java/org/mxchange/pizzaapplication/beans/controller/ShopWebBean.java index 32eb722f..d01efbc5 100644 --- a/src/java/org/mxchange/pizzaapplication/beans/controller/ShopWebBean.java +++ b/src/java/org/mxchange/pizzaapplication/beans/controller/ShopWebBean.java @@ -19,7 +19,7 @@ package org.mxchange.pizzaapplication.beans.controller; import java.util.Deque; import java.util.Queue; import javax.annotation.PostConstruct; -import javax.enterprise.context.SessionScoped; +import javax.enterprise.context.ApplicationScoped; import javax.faces.FacesException; import javax.faces.view.facelets.FaceletException; import javax.inject.Named; @@ -38,47 +38,70 @@ import org.mxchange.jshopcore.model.product.ProductSessionBeanRemote; * @author Roland Haeder */ @Named("controller") -@SessionScoped +@ApplicationScoped public class ShopWebBean extends BaseFrameworkBean implements ShopWebController { /** - * Serial id + * Serial number */ private static final long serialVersionUID = 58_137_539_530_279L; /** - * Remote bean for categories + * "Cache" for all available products */ - private final CategorySessionBeanRemote categoryBean; + private Deque availableProducts; /** - * Remote bean for products + * All categories */ - private final ProductSessionBeanRemote productBean; + private Deque categories; - /** - * Default constructor - * - * @throws javax.naming.NamingException Something happened here? - */ - public ShopWebBean () throws NamingException { - // Get initial context - InitialContext context = new InitialContext(); + @Override + public void addCategory (final Category category) { + // Add the category + this.categories.add(category); + } + + @Override + public void addProduct (final Product product) { + // Is the product available? + if (product.getAvailable()) { + // Add it + this.availableProducts.add(product); + } + } + + @PostConstruct + public void init () { + // Call super init for getting resource bundle + super.genericInit(); - // Try to lookup the bean - this.categoryBean = (CategorySessionBeanRemote) context.lookup("ejb/stateless-category"); //NOI18N + try { + // Get initial context + InitialContext context = new InitialContext(); - // Try to lookup the bean - this.productBean = (ProductSessionBeanRemote) context.lookup("ejb/stateless-product"); //NOI18N + // Try to lookup the bean + CategorySessionBeanRemote categoryBean = (CategorySessionBeanRemote) context.lookup("ejb/stateless-category"); //NOI18N + + // Get all categories + this.categories = categoryBean.getAllCategories(); + + // Try to lookup the bean + ProductSessionBeanRemote productBean = (ProductSessionBeanRemote) context.lookup("ejb/stateless-product"); //NOI18N + + // Get available products list + this.availableProducts = productBean.getAvailableProducts(); + } catch (final NamingException e) { + // Continued to throw + throw new FacesException(e); + } } @Override public Deque getAllCategories () throws FacesException { - // Get List back - Deque deque = this.getCategoryBean().getAllCategories(); - // Return it - return deque; + // TODO Find something better here to prevent warning + return this.categories; } @Override @@ -98,34 +121,8 @@ public class ShopWebBean extends BaseFrameworkBean implements ShopWebController @Override public Queue getAvailableProducts () throws FacesException { - // Get queue from bean - Queue queue = this.getProductBean().getAvailableProducts(); - // Return it - return queue; - } - - @PostConstruct - public void init () { - // Call super init for getting resource bundle - super.genericInit(); - } - - /** - * Getter for shop remote bean - * - * @return Remote shop bean - */ - private CategorySessionBeanRemote getCategoryBean () { - return this.categoryBean; - } - - /** - * Getter for shop remote bean - * - * @return Remote shop bean - */ - private ProductSessionBeanRemote getProductBean () { - return this.productBean; + // TODO Find something better here to prevent warning + return this.availableProducts; } } diff --git a/src/java/org/mxchange/pizzaapplication/beans/controller/ShopWebController.java b/src/java/org/mxchange/pizzaapplication/beans/controller/ShopWebController.java index 547c66e9..88e0b1c3 100644 --- a/src/java/org/mxchange/pizzaapplication/beans/controller/ShopWebController.java +++ b/src/java/org/mxchange/pizzaapplication/beans/controller/ShopWebController.java @@ -30,6 +30,20 @@ import org.mxchange.jshopcore.model.product.Product; */ public interface ShopWebController extends Serializable { + /** + * Adds given category to the "cached" instance + * + * @param category Category instance + */ + public void addCategory (final Category category); + + /** + * Adds given product to the "cached" instance + * + * @param product Product instance + */ + public void addProduct (final Product product); + /** * Some "getter" for a linked list of only available products * diff --git a/src/java/org/mxchange/pizzaapplication/beans/gender/GenderWebBean.java b/src/java/org/mxchange/pizzaapplication/beans/gender/GenderWebBean.java index e15647c0..c93c3995 100644 --- a/src/java/org/mxchange/pizzaapplication/beans/gender/GenderWebBean.java +++ b/src/java/org/mxchange/pizzaapplication/beans/gender/GenderWebBean.java @@ -19,10 +19,8 @@ package org.mxchange.pizzaapplication.beans.gender; import java.util.List; import javax.enterprise.context.ApplicationScoped; import javax.inject.Named; -import javax.naming.InitialContext; -import javax.naming.NamingException; import org.mxchange.jcore.model.contact.gender.Gender; -import org.mxchange.jcore.model.contact.gender.GenderSessionBeanRemote; +import org.mxchange.jcore.model.contact.gender.GenderUtils; import org.mxchange.jcoreee.beans.BaseFrameworkBean; /** @@ -39,46 +37,25 @@ public class GenderWebBean extends BaseFrameworkBean implements GenderWebControl */ private static final long serialVersionUID = 835_482_364_189L; - /** - * Remote bean - */ - private final GenderSessionBeanRemote genderBean; - /** * Default constructor - * - * @throws javax.naming.NamingException If something happens? */ - public GenderWebBean () throws NamingException { - // Get initial context - InitialContext context = new InitialContext(); - - // Try to lookup bean - this.genderBean = (GenderSessionBeanRemote) context.lookup("ejb/stateful-gender"); //NOI18N + public GenderWebBean () { } @Override public Gender[] getAllGenders () { // Return it - return this.getGenderBean().allGenders(); + return Gender.values(); } @Override public List getSelectableGenders () { // Init array // TODO Call EJB here? - List genders = this.getGenderBean().selectableGenders(); + List genders = GenderUtils.selectableGenders(); // Return it return genders; } - - /** - * Getter for data remote bean - * - * @return data remote bean - */ - private GenderSessionBeanRemote getGenderBean () { - return this.genderBean; - } } diff --git a/src/java/org/mxchange/pizzaapplication/beans/product/AdminProductWebBean.java b/src/java/org/mxchange/pizzaapplication/beans/product/AdminProductWebBean.java index 1e098fd3..c37417d8 100644 --- a/src/java/org/mxchange/pizzaapplication/beans/product/AdminProductWebBean.java +++ b/src/java/org/mxchange/pizzaapplication/beans/product/AdminProductWebBean.java @@ -19,14 +19,17 @@ package org.mxchange.pizzaapplication.beans.product; import java.util.Deque; import javax.enterprise.context.RequestScoped; import javax.faces.view.facelets.FaceletException; +import javax.inject.Inject; import javax.inject.Named; import javax.naming.InitialContext; import javax.naming.NamingException; import org.mxchange.jcoreee.beans.BaseFrameworkBean; +import org.mxchange.jshopcore.exceptions.CannotAddProductException; import org.mxchange.jshopcore.exceptions.ProductTitleAlreadyUsedException; import org.mxchange.jshopcore.model.product.GenericProduct; import org.mxchange.jshopcore.model.product.Product; import org.mxchange.jshopcore.model.product.ProductSessionBeanRemote; +import org.mxchange.pizzaapplication.beans.controller.ShopWebController; /** * Main application class @@ -38,7 +41,7 @@ import org.mxchange.jshopcore.model.product.ProductSessionBeanRemote; public class AdminProductWebBean extends BaseFrameworkBean implements AdminProductWebController { /** - * Serial id + * Serial number */ private static final long serialVersionUID = 5_819_375_183_472_871L; @@ -63,6 +66,12 @@ public class AdminProductWebBean extends BaseFrameworkBean implements AdminProdu */ private final ProductSessionBeanRemote productBean; + /** + * Shop bean + */ + @Inject + private ShopWebController controller; + /** * Property title */ @@ -96,12 +105,15 @@ public class AdminProductWebBean extends BaseFrameworkBean implements AdminProdu // Call bean this.productBean.doAdminAddProduct(product); + // Add to shop controller + this.controller.addProduct(product); + // Set all to null this.setAvailable(Boolean.FALSE); this.setId(null); this.setPrice(null); this.setTitle(null); - } catch (final ProductTitleAlreadyUsedException ex) { + } catch (final ProductTitleAlreadyUsedException | CannotAddProductException ex) { // Continue to throw throw new FaceletException(ex); } diff --git a/web/WEB-INF/faces-config.xml b/web/WEB-INF/faces-config.xml index 4a8b5573..46fa5720 100644 --- a/web/WEB-INF/faces-config.xml +++ b/web/WEB-INF/faces-config.xml @@ -11,6 +11,10 @@ NameValidator org.mxchange.jcoreee.validator.string.names.NameValidator + + ItemAmountValidator + org.mxchange.jcoreee.validator.number.item_amount.ItemAmountValidator + * @@ -59,7 +63,7 @@ basket - /basket.xhtml + /basketController.xhtml diff --git a/web/WEB-INF/glassfish-web.xml b/web/WEB-INF/glassfish-web.xml index 730d5867..eaf64487 100644 --- a/web/WEB-INF/glassfish-web.xml +++ b/web/WEB-INF/glassfish-web.xml @@ -1,11 +1,11 @@ - /PizzaService-war - - - - Keep a copy of the generated servlet class' java code. - - + /PizzaService-war + + + + Keep a copy of the generated servlet class' java code. + + diff --git a/web/WEB-INF/templates/basket/mini_basket.tpl b/web/WEB-INF/templates/basket/mini_basket.tpl index 050ca2ce..409b3056 100644 --- a/web/WEB-INF/templates/basket/mini_basket.tpl +++ b/web/WEB-INF/templates/basket/mini_basket.tpl @@ -6,19 +6,19 @@
- #{msg.mini_basket.header} + #{msg.mini_basketController.header}
- #{msg.mini_basket.last_item} + #{msg.mini_basketController.last_item}
- #{msg.mini_basket.additional_items} + #{msg.mini_basketController.additional_items}
diff --git a/web/WEB-INF/templates/guest/guest_base.tpl b/web/WEB-INF/templates/guest/guest_base.tpl index ee4ced7e..ec484010 100644 --- a/web/WEB-INF/templates/guest/guest_base.tpl +++ b/web/WEB-INF/templates/guest/guest_base.tpl @@ -6,12 +6,12 @@ - + - - + + diff --git a/web/WEB-INF/tlds/basket.tld b/web/WEB-INF/tlds/basket.tld index e87d2592..aff9f901 100644 --- a/web/WEB-INF/tlds/basket.tld +++ b/web/WEB-INF/tlds/basket.tld @@ -8,13 +8,13 @@ mini_basket A mini basket showing latest added item and a link to the full basket web page - org.mxchange.pizzaapplication.tags.basket.MiniBasketTag + org.mxchange.pizzaapplication.tags.basketController.MiniBasketTag basket Basket instance, should be the same as the bean true true - org.mxchange.jshopejb.beans.basket.BasketBean + org.mxchange.jshopejb.beans.basketController.BasketBean diff --git a/web/index.xhtml b/web/index.xhtml index e612d608..aa0f9083 100644 --- a/web/index.xhtml +++ b/web/index.xhtml @@ -22,117 +22,51 @@ - - - - - - - - - - - - - - - - - - - - -
- Folgendes kann bestellt werden: -
- Bestellen? - - Anzahl: - - Produkt: - - Einzelpreis: - - Zwischensumme: -
- - - - - - - - - - - - - - - - - -
- - - #{basket.currentItem.amount} - - #{product.title} - - - - - - - - -
-
- - - - - - - - - - - - - - - - - -
- - - - - - - - #{product.title} - - - - - - - -
-
-
-
+ +
+
+ Folgendes kann bestellt werden: +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
-- 2.39.5