From ac5e656620924ab0a81b244fbf4cbfe11145ef59 Mon Sep 17 00:00:00 2001 From: Roland Haeder Date: Thu, 13 Aug 2015 10:14:56 +0200 Subject: [PATCH] =?utf8?q?Introduced=20markAllChoosenProductsAsOrdered()?= =?utf8?q?=20and=20used=20forEach=20from=20taglib=20Signed-off-by:Roland?= =?utf8?q?=20H=C3=A4der=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../application/PizzaApplication.java | 9 ++++ .../application/PizzaServiceApplication.java | 41 +++++++++++++++++++ web/admin/category.jsp | 32 +++++++-------- web/admin/product.jsp | 39 ++++++++---------- web/form_handler/do_order.jsp | 5 ++- 5 files changed, 85 insertions(+), 41 deletions(-) diff --git a/src/java/org/mxchange/pizzaapplication/application/PizzaApplication.java b/src/java/org/mxchange/pizzaapplication/application/PizzaApplication.java index 38487981..89f46456 100644 --- a/src/java/org/mxchange/pizzaapplication/application/PizzaApplication.java +++ b/src/java/org/mxchange/pizzaapplication/application/PizzaApplication.java @@ -226,4 +226,13 @@ public interface PizzaApplication extends Application { * @return Human-readable version of product availability */ public String getPrintableProduktAvailability (final Product product); + + /** + * Marks all choosen products as ordered + * + * @param request Request instance + * @param session Session instance + * @throws javax.servlet.ServletException If something unexpected happened + */ + public void markAllChoosenProductsAsOrdered (final HttpServletRequest request, final HttpSession session) throws ServletException; } diff --git a/src/java/org/mxchange/pizzaapplication/application/PizzaServiceApplication.java b/src/java/org/mxchange/pizzaapplication/application/PizzaServiceApplication.java index 0c8914f8..30e1368d 100644 --- a/src/java/org/mxchange/pizzaapplication/application/PizzaServiceApplication.java +++ b/src/java/org/mxchange/pizzaapplication/application/PizzaServiceApplication.java @@ -39,6 +39,7 @@ import org.mxchange.pizzaapplication.database.frontend.product.ProductFrontend; import org.mxchange.pizzaapplication.product.Product; /** + * Main application class * * @author Roland Haeder */ @@ -735,6 +736,46 @@ public class PizzaServiceApplication extends BasePizzaServiceSystem implements P return (!amount.isEmpty() && !"0".equals(amount)); //NOI18N } + /** + * Marks all choosen products as ordered + * + * @param request Request instance + * @param session Session instance + */ + @Override + public void markAllChoosenProductsAsOrdered (final HttpServletRequest request, final HttpSession session) throws ServletException { + // Trace message + this.getLogger().trace(MessageFormat.format("request={0},session={1} - CALLED!", request, session)); + + // Init iterator + Iterator iterator; + + try { + // Get iterator + iterator = this.getProducts(); + } catch (final IOException | BadTokenException ex) { + throw new ServletException(ex); + } + + // "Walk" over all products + while (iterator.hasNext()) { + // Get next product + Product product = iterator.next(); + + // Debug message + this.getLogger().debug(MessageFormat.format("product={0}", product)); + + // Is it choosen? + if (this.isProductChoosen(product, request, session)) { + // Mark product as ordered + this.markProductAsOrdered(product, session); + } + } + + // Trace message + this.getLogger().trace("EXIT!"); + } + /** * Marks given product as choosen in session * diff --git a/web/admin/category.jsp b/web/admin/category.jsp index 1dc87c57..35e87919 100644 --- a/web/admin/category.jsp +++ b/web/admin/category.jsp @@ -4,6 +4,7 @@ Author : Roland Haeder --%> +<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> <%--<%@page errorPage="errorHandler.jsp" %>--%> <%@page import="org.mxchange.pizzaapplication.category.Category"%> <%@page import="org.mxchange.pizzaapplication.application.PizzaServiceApplication"%> @@ -54,24 +55,19 @@ - <% - // "Walk" through all products and unmark them as ordered - for (final Category category : app.getCategories()) { - %> - - - <%=category.getId()%> - - - <%=category.getTitle()%> - - - <%=category.getPrice()%> - - - <% - } - %> + + + + ${category.getId()} + + + ${category.getTitle()} + + + ${category.getPrice()} + + + diff --git a/web/admin/product.jsp b/web/admin/product.jsp index 1efbefef..453f70cc 100644 --- a/web/admin/product.jsp +++ b/web/admin/product.jsp @@ -4,6 +4,7 @@ Author : Roland Haeder --%> +<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> <%--<%@page errorPage="errorHandler.jsp" %>--%> <%@page import="java.util.Iterator"%> <%@page import="java.util.Map"%> @@ -59,28 +60,22 @@ - <% - // "Walk" through all products and unmark them as ordered - for (final Product product : app.getProducts()) { - %> - - - <%=product.getId()%> - - - <%=product.getTitle()%> - - - <%=product.getPrice()%> - - - <%=app.getPrintableProduktAvailability(product)%> - - - <% - } - %> - + + + + ${product.getId()} + + + ${product.getTitle()} + + + ${product.getPrice()} + + + ${app.getPrintableProduktAvailability(product)} + + + diff --git a/web/form_handler/do_order.jsp b/web/form_handler/do_order.jsp index e283043a..e0901b2a 100644 --- a/web/form_handler/do_order.jsp +++ b/web/form_handler/do_order.jsp @@ -17,7 +17,10 @@ // Is it post? if ("POST".equals(request.getMethod())) { //NOI18N - // Handle saving customer data and such things + // @TODO Handle saving customer data and such things + + // Mark all choosen products as ordered + app.markAllChoosenProductsAsOrdered(request, session); // Redirect to proper URL // @TODO Commented out for developing: -- 2.39.5