]> git.mxchange.org Git - pizzaservice-war.git/commitdiff
Introduced markAllChoosenProductsAsOrdered() and used forEach from taglib
authorRoland Haeder <roland@mxchange.org>
Thu, 13 Aug 2015 08:14:56 +0000 (10:14 +0200)
committerRoland Haeder <roland@mxchange.org>
Thu, 13 Aug 2015 13:36:11 +0000 (15:36 +0200)
Signed-off-by:Roland Häder <roland@mxchange.org>

src/java/org/mxchange/pizzaapplication/application/PizzaApplication.java
src/java/org/mxchange/pizzaapplication/application/PizzaServiceApplication.java
web/admin/category.jsp
web/admin/product.jsp
web/form_handler/do_order.jsp

index 38487981be35699f260359758ccf5369afd0fb0d..89f46456a72bf676fcccc36f4b446e5abb2ec52a 100644 (file)
@@ -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;
 }
index 0c8914f8e493bfb5ad81bf4fb685e94ca9904794..30e1368d54f7a2fc52020248356f5f3533ae1e6f 100644 (file)
@@ -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<Product> 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
         *
index 1dc87c57080017b992566708f881d44a2aaefc9f..35e879197291d3febd7b08d079aa5ed4cc211d73 100644 (file)
@@ -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"%>
                                                </thead>
 
                                                <tbody class="table_body">
-                                                       <%
-                                                       // "Walk" through all products and unmark them as ordered
-                                                       for (final Category category : app.getCategories()) {
-                                                               %>
-                                                               <tr>
-                                                                       <td>
-                                                                               <%=category.getId()%>
-                                                                       </td>
-                                                                       <td>
-                                                                               <%=category.getTitle()%>
-                                                                       </td>
-                                                                       <td>
-                                                                               <%=category.getPrice()%>
-                                                                       </td>
-                                                               </tr>
-                                                               <%
-                                                       }
-                                                       %>
+                                                       <c:forEach var="category" items="<%=app.getCategories()%>">
+                                                       <tr>
+                                                               <td>
+                                                                       ${category.getId()}
+                                                               </td>
+                                                               <td>
+                                                                       ${category.getTitle()}
+                                                               </td>
+                                                               <td>
+                                                                       ${category.getPrice()}
+                                                               </td>
+                                                       </tr>
+                                                       </c:forEach>
 
                                                        <tr>
                                                                <td colspan="3" class="table_footer">
index 1efbefefd46b6efbf9f97057c7e5b111d91eba10..453f70ccf53694560b94327568c79e39409b3225 100644 (file)
@@ -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"%>
                                                </thead>
 
                                                <tbody class="table_body">
-                                                       <%
-                                                       // "Walk" through all products and unmark them as ordered
-                                                       for (final Product product : app.getProducts()) {
-                                                               %>
-                                                               <tr>
-                                                                       <td>
-                                                                               <%=product.getId()%>
-                                                                       </td>
-                                                                       <td>
-                                                                               <%=product.getTitle()%>
-                                                                       </td>
-                                                                       <td>
-                                                                               <%=product.getPrice()%>
-                                                                       </td>
-                                                                       <td>
-                                                                               <%=app.getPrintableProduktAvailability(product)%>
-                                                                       </td>
-                                                               </tr>
-                                                               <%
-                                                       }
-                                                       %>
-
+                                                       <c:forEach var="product" items="<%=app.getProducts()%>">
+                                                       <tr>
+                                                               <td>
+                                                                       ${product.getId()}
+                                                               </td>
+                                                               <td>
+                                                                       ${product.getTitle()}
+                                                               </td>
+                                                               <td>
+                                                                       ${product.getPrice()}
+                                                               </td>
+                                                               <td>
+                                                                       ${app.getPrintableProduktAvailability(product)}
+                                                               </td>
+                                                       </tr>
+                                                       </c:forEach>
                                                        <tr>
                                                                <td colspan="4" class="table_footer">
                                                                        <input type="reset" value="Formular zurücksetzen" />
index e283043a8cf9e25f875808a091d44df6a451c9f4..e0901b2a3de09bd6099d3f62d8a162f8a25d1636 100644 (file)
 
        // 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: