From: Roland Haeder Date: Tue, 11 Aug 2015 09:22:13 +0000 (+0200) Subject: Now that instance product has no method to mark it as choosen (bad idea as all users... X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=49a4e16d44cd9fa16f0e7d48d097efbd537cb827;p=pizzaservice-war.git Now that instance product has no method to mark it as choosen (bad idea as all users will have it choosen then) there needs to be added a new method for this Signed-off-by:Roland Häder --- 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); } } %>