From 49a4e16d44cd9fa16f0e7d48d097efbd537cb827 Mon Sep 17 00:00:00 2001 From: Roland Haeder Date: Tue, 11 Aug 2015 11:22:13 +0200 Subject: [PATCH] =?utf8?q?Now=20that=20instance=20product=20has=20no=20met?= =?utf8?q?hod=20to=20mark=20it=20as=20choosen=20(bad=20idea=20as=20all=20u?= =?utf8?q?sers=20will=20have=20it=20choosen=20then)=20there=20needs=20to?= =?utf8?q?=20be=20added=20a=20new=20method=20for=20this=20Signed-off-by:Ro?= =?utf8?q?land=20H=C3=A4der=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../application/PizzaApplication.java | 8 ++++++ .../application/PizzaServiceApplication.java | 28 +++++++++++++++++++ web/preview.jsp | 6 ++-- 3 files changed, 39 insertions(+), 3 deletions(-) diff --git a/src/java/org/mxchange/pizzaapplication/application/PizzaApplication.java b/src/java/org/mxchange/pizzaapplication/application/PizzaApplication.java index 4f3ca4af..93d0d933 100644 --- a/src/java/org/mxchange/pizzaapplication/application/PizzaApplication.java +++ b/src/java/org/mxchange/pizzaapplication/application/PizzaApplication.java @@ -160,6 +160,14 @@ public interface PizzaApplication extends Application { */ public void markProductAsOrdered(final Product product, final HttpSession session); + /** + * Marks given product as choosen in session + * + * @param product Product to mark as ordered + * @param session Session instance + */ + public void markProductAsChoosen(final Product product, final HttpSession session); + /** * Unmarks given product as ordered in session * diff --git a/src/java/org/mxchange/pizzaapplication/application/PizzaServiceApplication.java b/src/java/org/mxchange/pizzaapplication/application/PizzaServiceApplication.java index 5a834938..647ab179 100644 --- a/src/java/org/mxchange/pizzaapplication/application/PizzaServiceApplication.java +++ b/src/java/org/mxchange/pizzaapplication/application/PizzaServiceApplication.java @@ -1030,4 +1030,32 @@ public class PizzaServiceApplication extends BasePizzaServiceSystem implements P public Product[] getProducts () { return (Product[]) this.products.values().toArray(); } + + /** + * Marks given product as choosen in session + * + * @param product Product to mark as ordered + * @param session Session instance + */ + @Override + public void markProductAsChoosen(final Product product, final HttpSession session) { + // Trace message + this.getLogger().trace(MessageFormat.format("product={0},session={1} - CALLED!", product, session)); //NOI18N + + // Is product and session set? + if (product == null) { + // Not set + throw new NullPointerException("product is null"); //NOI18N + } else if (session == null) { + // Not set + throw new NullPointerException("session is null"); //NOI18N + } + + // Mark it as ordered by setting flag + this.getLogger().debug(MessageFormat.format("Marking product={0} as choosen.", product.getName())); //NOI18N + this.setValueInSession(product, session, HTTP_PARAM_CHOOSE, "1"); + + // Trace message + this.getLogger().trace("EXIT!"); //NOI18N + } } diff --git a/web/preview.jsp b/web/preview.jsp index 86d3832e..7002f658 100644 --- a/web/preview.jsp +++ b/web/preview.jsp @@ -65,7 +65,8 @@ <% - for (final Product product : app.getProducts()) { + // "Walk" through all products and unmark them as ordered + for (final Product product : app.getUnmarkedProducts(session)) { %> @@ -88,8 +89,7 @@ // Is it choosen and amount set? if (app.isProductChoosen(product, request, session)) { // Then mark it as choosen - product.markAsChoosen(); - app.unmarkProductAsOrdered(product, session); + app.markProductAsChoosen(product, session); } } %> -- 2.39.5