From: Roland Haeder Date: Sat, 22 Aug 2015 11:25:31 +0000 (+0200) Subject: The item bean must go into request scope, else all added items have same amount ... X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=c648138b584d4f1a8656a39a9fff494e979f6610;p=pizzaservice-war.git The item bean must go into request scope, else all added items have same amount + began to cleanup rudimentary JSPs for a basket-based approach Signed-off-by:Roland Häder --- diff --git a/nbproject/project.properties b/nbproject/project.properties index 9b0677ea..d63eef99 100644 --- a/nbproject/project.properties +++ b/nbproject/project.properties @@ -36,11 +36,11 @@ j2ee.compile.on.save=true j2ee.copy.static.files.on.save=true j2ee.deploy.on.save=true j2ee.platform=1.5 -j2ee.platform.classpath=${j2ee.server.middleware}/mq/lib/jaxm-api.jar:${j2ee.server.home}/modules/endorsed/javax.annotation-api.jar:${j2ee.server.home}/modules/endorsed/jaxb-api-osgi.jar:${j2ee.server.home}/modules/endorsed/webservices-api-osgi.jar:${j2ee.server.home}/modules/bean-validator.jar:${j2ee.server.home}/modules/javax.batch-api.jar:${j2ee.server.home}/modules/javax.ejb-api.jar:${j2ee.server.home}/modules/javax.el.jar:${j2ee.server.home}/modules/javax.enterprise.concurrent-api.jar:${j2ee.server.home}/modules/javax.enterprise.concurrent.jar:${j2ee.server.home}/modules/javax.enterprise.deploy-api.jar:${j2ee.server.home}/modules/javax.faces.jar:${j2ee.server.home}/modules/javax.inject.jar:${j2ee.server.home}/modules/javax.interceptor-api.jar:${j2ee.server.home}/modules/javax.jms-api.jar:${j2ee.server.home}/modules/javax.json.jar:${j2ee.server.home}/modules/javax.mail.jar:${j2ee.server.home}/modules/javax.management.j2ee-api.jar:${j2ee.server.home}/modules/javax.persistence.jar:${j2ee.server.home}/modules/javax.resource-api.jar:${j2ee.server.home}/modules/javax.security.auth.message-api.jar:${j2ee.server.home}/modules/javax.security.jacc-api.jar:${j2ee.server.home}/modules/javax.servlet-api.jar:${j2ee.server.home}/modules/javax.servlet.jsp-api.jar:${j2ee.server.home}/modules/javax.servlet.jsp.jar:${j2ee.server.home}/modules/javax.servlet.jsp.jstl-api.jar:${j2ee.server.home}/modules/javax.servlet.jsp.jstl.jar:${j2ee.server.home}/modules/javax.transaction-api.jar:${j2ee.server.home}/modules/javax.websocket-api.jar:${j2ee.server.home}/modules/javax.ws.rs-api.jar:${j2ee.server.home}/modules/javax.xml.registry-api.jar:${j2ee.server.home}/modules/javax.xml.rpc-api.jar:${j2ee.server.home}/modules/jaxb-osgi.jar:${j2ee.server.home}/modules/webservices-osgi.jar:${j2ee.server.home}/modules/weld-osgi-bundle.jar +j2ee.platform.classpath=${j2ee.server.middleware}/mq/lib/jaxm-api.jar:${j2ee.server.home}/modules/endorsed/javax.annotation-api.jar:${j2ee.server.home}/modules/endorsed/webservices-api-osgi.jar:${j2ee.server.home}/modules/endorsed/jaxb-api.jar:${j2ee.server.home}/modules/javax.batch-api.jar:${j2ee.server.home}/modules/javax.security.auth.message-api.jar:${j2ee.server.home}/modules/javax.faces.jar:${j2ee.server.home}/modules/javax.servlet.jsp.jstl-api.jar:${j2ee.server.home}/modules/javax.transaction-api.jar:${j2ee.server.home}/modules/javax.servlet.jsp.jar:${j2ee.server.home}/modules/webservices-osgi.jar:${j2ee.server.home}/modules/javax.mail.jar:${j2ee.server.home}/modules/javax.interceptor-api.jar:${j2ee.server.home}/modules/javax.inject.jar:${j2ee.server.home}/modules/javax.resource-api.jar:${j2ee.server.home}/modules/javax.enterprise.concurrent-api.jar:${j2ee.server.home}/modules/javax.el.jar:${j2ee.server.home}/modules/javax.ejb-api.jar:${j2ee.server.home}/modules/javax.xml.rpc-api.jar:${j2ee.server.home}/modules/javax.security.jacc-api.jar:${j2ee.server.home}/modules/javax.json.jar:${j2ee.server.home}/modules/javax.xml.registry-api.jar:${j2ee.server.home}/modules/javax.websocket-api.jar:${j2ee.server.home}/modules/javax.management.j2ee-api.jar:${j2ee.server.home}/modules/javax.servlet-api.jar:${j2ee.server.home}/modules/javax.jms-api.jar:${j2ee.server.home}/modules/javax.enterprise.concurrent.jar:${j2ee.server.home}/modules/javax.servlet.jsp.jstl.jar:${j2ee.server.home}/modules/javax.enterprise.deploy-api.jar:${j2ee.server.home}/modules/bean-validator.jar:${j2ee.server.home}/modules/javax.ws.rs-api.jar:${j2ee.server.home}/modules/javax.servlet.jsp-api.jar:${j2ee.server.home}/modules/jaxb-osgi.jar:${j2ee.server.home}/modules/weld-osgi-bundle.jar:${j2ee.server.home}/modules/javax.persistence.jar j2ee.platform.embeddableejb.classpath=${j2ee.server.home}/lib/embedded/glassfish-embedded-static-shell.jar j2ee.platform.wscompile.classpath=${j2ee.server.home}/modules/webservices-osgi.jar -j2ee.platform.wsgen.classpath=${j2ee.server.home}/modules/webservices-osgi.jar:${j2ee.server.home}/modules/endorsed/webservices-api-osgi.jar:${j2ee.server.home}/modules/jaxb-osgi.jar:${j2ee.server.home}/modules/endorsed/jaxb-api-osgi.jar -j2ee.platform.wsimport.classpath=${j2ee.server.home}/modules/webservices-osgi.jar:${j2ee.server.home}/modules/endorsed/webservices-api-osgi.jar:${j2ee.server.home}/modules/jaxb-osgi.jar:${j2ee.server.home}/modules/endorsed/jaxb-api-osgi.jar +j2ee.platform.wsgen.classpath=${j2ee.server.home}/modules/webservices-osgi.jar:${j2ee.server.home}/modules/endorsed/webservices-api-osgi.jar:${j2ee.server.home}/modules/jaxb-osgi.jar:${j2ee.server.home}/modules/endorsed/jaxb-api.jar +j2ee.platform.wsimport.classpath=${j2ee.server.home}/modules/webservices-osgi.jar:${j2ee.server.home}/modules/endorsed/webservices-api-osgi.jar:${j2ee.server.home}/modules/jaxb-osgi.jar:${j2ee.server.home}/modules/endorsed/jaxb-api.jar j2ee.platform.wsit.classpath= j2ee.server.type=gfv3ee6 jar.compress=false diff --git a/src/java/org/mxchange/pizzaapplication/basket/BaseBasket.java b/src/java/org/mxchange/pizzaapplication/basket/BaseBasket.java index ffd62df2..be976ece 100644 --- a/src/java/org/mxchange/pizzaapplication/basket/BaseBasket.java +++ b/src/java/org/mxchange/pizzaapplication/basket/BaseBasket.java @@ -93,11 +93,20 @@ public class BaseBasket extends BaseFrameworkSystem implements Basket basket; try { + // Get session instance + HttpSession session = ((HttpServletRequest) request).getSession(); + + // Debug message + this.getLogger().debug(MessageFormat.format("session={0}", session)); //NOI18N + + // Should not be null + if (session == null) { + // session is null + throw new NullPointerException("session is null"); //NOI18N + } + + // Get basket instance basket = ItemBasket.getInstance(session); } catch (final UnsupportedDatabaseBackendException | SQLException ex) { // Continue to throw @@ -99,7 +100,13 @@ public class BasketItemAddedFilter extends BaseServletFilter implements Filter { } // Is the item already added? - if (basket.isItemAdded(item)) { + if ((item.getAmount() == null) || (item.getAmount() == 0)) { + // Debug message + this.getLogger().debug("Amount for item " + item + " is null"); + + // Amount is not entered + return; + } else if (basket.isItemAdded(item)) { // Yes, then throw exception here throw new ServletException(MessageFormat.format("item id={0} has already been added.", item.getId())); } diff --git a/web/finished.jsp b/web/finished.jsp deleted file mode 100644 index b239762d..00000000 --- a/web/finished.jsp +++ /dev/null @@ -1,167 +0,0 @@ -<%-- - Document : finished - Created on : 04.08.2015, 10:55:47 - Author : Roland Haeder ---%> - -<%--<%@page errorPage="errorHandler.jsp" %>--%> -<%@page contentType="text/html" pageEncoding="UTF-8"%> - -<%@page import="java.lang.reflect.Field"%> -<%@page import="java.util.Map"%> -<%@page import="java.util.Iterator"%> -<%@page import="org.mxchange.pizzaapplication.application.PizzaApplication"%> -<%@page import="org.mxchange.pizzaapplication.application.PizzaServiceApplication"%> -<%@page import="org.mxchange.pizzaapplication.beans.CustomerBean" %> -<%@page import="org.mxchange.pizzaapplication.product.Product"%> - - - - -<% - // Init application instance - PizzaApplication app = PizzaServiceApplication.getInstance(application); -%> - - - - - - <%=PizzaServiceApplication.MAIN_TITLE%> - Vielen Dank! - - - - - - - -
-
-

Folgendes haben Sie bestellt:

-
- -
- - - - - - - - - - - - <% - // Get Iterator - Iterator iterator = app.getAvailableProducts(); - - // "Walk" through all products and unmark them as ordered - while (iterator.hasNext()) { - // Get product instance - Product product = iterator.next(); - %> - - - - - - - - <% - } - %> - - - - - - - - - - - - - - - - - - - - -
- Bestellen? - - Anzahl: - - Produkt: - - Einzelpreis: - - Zwischensumme: -
- <%=app.getPrintableChoosenFromRequestSession(product, request, session)%> - - <%=app.handleAmountFromRequestSession(product, request, session)%> - - <%=product.getTitle()%> - - <%=product.getPrice()%> - - <%=app.getTotalPositionPriceFromRequestSession(product, request, session)%> -
- Menge: - - <%=app.calculateTotalAmount(request, session)%> - -   - - Gesamtpreis: - - <%=app.calculateTotalPrice(request, session)%> -
- Ihre Daten: -
- <% - // Debug message - app.getLogger().debug("customer=" + customer); - - // Get iterator on all fields/attributes - Iterator> fieldIterator = customer.iterator(); - %> -
    - <% - while (fieldIterator.hasNext()) { - Map.Entry entry = fieldIterator.next(); - %> -
  • <%=entry.getKey().getName()%> set to: <%=entry.getValue()%>
  • - <% - } - %> -
-
-
-
- - - - diff --git a/web/form_handler/add_item.jsp b/web/form_handler/add_item.jsp index 3e033fc6..9c069262 100644 --- a/web/form_handler/add_item.jsp +++ b/web/form_handler/add_item.jsp @@ -10,15 +10,27 @@ <%@page import="org.mxchange.pizzaapplication.application.PizzaServiceApplication"%> <%@page import="org.mxchange.pizzaapplication.item.AddableBasketItem"%> - + <% // Init application instance PizzaApplication app = PizzaServiceApplication.getInstance(application); - // Redirect to proper URL - response.sendRedirect(request.getContextPath() + "/?add=1"); + // Get amount from item + Long amount = item.getAmount(); + + // Debug message + app.getLogger().debug("amount=" + amount); + + // Is amount null or zero? + if ((amount == null) || (amount == 0)) { + // Then redirect to added=0 + response.sendRedirect(request.getContextPath() + "/?add=0"); + } else { + // Redirect to proper URL + response.sendRedirect(request.getContextPath() + "/?add=1"); + } %> @@ -37,5 +49,7 @@ + + diff --git a/web/preview.jsp b/web/preview.jsp deleted file mode 100644 index ca5c788e..00000000 --- a/web/preview.jsp +++ /dev/null @@ -1,145 +0,0 @@ -<%-- - Document : preview - Created on : 04.08.2015, 10:55:10 - 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"%> -<%@page import="org.mxchange.jcore.contact.Gender"%> -<%@page import="org.mxchange.pizzaapplication.product.Product"%> -<%@page import="org.mxchange.pizzaapplication.application.PizzaApplication"%> -<%@page import="org.mxchange.pizzaapplication.application.PizzaServiceApplication"%> -<%@page import="org.mxchange.pizzaapplication.beans.CustomerBean" %> -<%@page contentType="text/html" pageEncoding="UTF-8"%> - - - - -<% - // Init application instance - PizzaApplication app = PizzaServiceApplication.getInstance(application); -%> - - - - - - <%=PizzaServiceApplication.MAIN_TITLE%> - Bestellung anzeigen - - - - - - - -
-
-

Folgendes möchten Sie bestellen:

-
- -
-
- - - - - - - - - - - - <% - // Get Iterator - Iterator iterator = app.getAvailableProducts(); - - // "Walk" through all products and unmark them as ordered - while (iterator.hasNext()) { - // Get product instance - Product product = iterator.next(); - - // Unmark it as ordered - app.unmarkProductAsOrdered(product, session); - %> - - - - - - - - <% - // Is it choosen and amount set? - if (app.isProductChoosen(product, request, session)) { - // Then mark it as choosen - app.markProductAsChoosen(product, session); - } - } - %> - - - - - - - - - - - - - - - - -
- Bestellen? - - Anzahl: - - Produkt: - - Einzelpreis: - - Zwischensumme: -
- <%=app.getPrintableChoosenFromRequestSession(product, request, session)%> - - <%=app.handleAmountFromRequestSession(product, request, session)%> - - <%=product.getTitle()%> - - <%=product.getPrice()%> - - <%=app.getTotalPositionPriceFromRequestSession(product, request, session)%> -
- Menge: - - <%=app.calculateTotalAmount(request, session)%> - -   - - Gesamtpreis: - - <%=app.calculateTotalPrice(request, session)%> -
- <%-- @TODO Add navigation to login and registration form --%> -
-
-
-
- - - - diff --git a/web/static/menu.jsp b/web/static/menu.jsp index d5b6493e..a1d68508 100644 --- a/web/static/menu.jsp +++ b/web/static/menu.jsp @@ -7,8 +7,6 @@