From: Roland Haeder Date: Fri, 7 Aug 2015 13:49:41 +0000 (+0200) Subject: Introduced setValueInSession() + order.jsp form handler (broken, why?) X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=46ed5739fee5853054618771d5c9cdcb07e355ff;p=pizzaservice-war.git Introduced setValueInSession() + order.jsp form handler (broken, why?) 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 9cc5ba6d..42b02c8f 100644 --- a/src/java/org/mxchange/pizzaapplication/application/PizzaApplication.java +++ b/src/java/org/mxchange/pizzaapplication/application/PizzaApplication.java @@ -185,4 +185,13 @@ public interface PizzaApplication extends Application { * @return Value from key, empty string for null */ public Object getPrintableValeFromSession (final HttpSession session, final String key); + + /** + * Somewhat setter in session + * + * @param session Session instance + * @param key Session key to set + * @param value Value to set + */ + public void setValueInSession (final HttpSession session, final String key, final Object value); } diff --git a/src/java/org/mxchange/pizzaapplication/application/PizzaServiceApplication.java b/src/java/org/mxchange/pizzaapplication/application/PizzaServiceApplication.java index 27afd321..163075e5 100644 --- a/src/java/org/mxchange/pizzaapplication/application/PizzaServiceApplication.java +++ b/src/java/org/mxchange/pizzaapplication/application/PizzaServiceApplication.java @@ -304,8 +304,29 @@ public class PizzaServiceApplication extends BasePizzaServiceSystem implements P synchronized(session) { // Set it synced - this.getLogger().debug(MessageFormat.format("setValueInSession: Setting value={0} for product={1},keyPart={2}", value, product.getName(), keyPart)); //NOI18N - session.setAttribute(String.format(HTTP_PARAM_MASK, product.getName(), keyPart), value); + this.getLogger().debug(MessageFormat.format("Setting value={0} for product={1},keyPart={2}", value, product.getName(), keyPart)); //NOI18N + this.setValueInSession(session, String.format(HTTP_PARAM_MASK, product.getName(), keyPart), value); + } + + // Trace message + this.getLogger().trace("EXIT!"); //NOI18N + } + + /** + * Somewhat setter in session + * + * @param session Session instance + * @param key Session key to set + * @param value Value to set + */ + @Override + public void setValueInSession (final HttpSession session, final String key, final Object value) { + // Trace message + this.getLogger().trace(MessageFormat.format("session={0},key={1},value={2} - CALLED!", session, key, value)); //NOI18N + + synchronized(session) { + // Set it synced + session.setAttribute(key, value); } // Trace message diff --git a/src/java/org/mxchange/pizzaapplication/customer/bean/PizzaServiceCustomerBean.java b/src/java/org/mxchange/pizzaapplication/customer/bean/PizzaServiceCustomerBean.java index 98a5a6a9..3b7de4c2 100644 --- a/src/java/org/mxchange/pizzaapplication/customer/bean/PizzaServiceCustomerBean.java +++ b/src/java/org/mxchange/pizzaapplication/customer/bean/PizzaServiceCustomerBean.java @@ -39,6 +39,9 @@ public class PizzaServiceCustomerBean extends BasePizzaServiceSystem implements // Instance customer Contact customer = new PizzaServiceCustomer(); + // Fake gender + customer.setGender(Gender.UNKNOWN); + // And set it here this.setContact(customer); } @@ -164,13 +167,13 @@ public class PizzaServiceCustomerBean extends BasePizzaServiceSystem implements } @Override - public long getHouseNumber () { + public Long getHouseNumber () { // Deligate to "hidden" object return this.getContact().getHouseNumber(); } @Override - public void setHouseNumber (final long houseNumber) { + public void setHouseNumber (final Long houseNumber) { // Deligate to "hidden" object this.getContact().setHouseNumber(houseNumber); } @@ -218,13 +221,13 @@ public class PizzaServiceCustomerBean extends BasePizzaServiceSystem implements } @Override - public long getZipCode () { + public Long getZipCode () { // Deligate to "hidden" object return this.getContact().getZipCode(); } @Override - public void setZipCode (final long zipCode) { + public void setZipCode (final Long zipCode) { // Deligate to "hidden" object this.getContact().setZipCode(zipCode); } diff --git a/web/bye.jsp b/web/bye.jsp index f58324ef..acf5b790 100644 --- a/web/bye.jsp +++ b/web/bye.jsp @@ -21,7 +21,7 @@
diff --git a/web/errorHandler.jsp b/web/errorHandler.jsp index 813977e0..0f45fade 100644 --- a/web/errorHandler.jsp +++ b/web/errorHandler.jsp @@ -9,7 +9,9 @@ <%@page import="java.io.PrintWriter"%> <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> <%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %> -<% + + +<% // Init application instance PizzaApplication app = PizzaServiceApplication.getInstance(application); %> @@ -27,7 +29,7 @@
diff --git a/web/finished.jsp b/web/finished.jsp index ab7d9498..012a8282 100644 --- a/web/finished.jsp +++ b/web/finished.jsp @@ -4,10 +4,10 @@ Author : Roland Haeder --%> -<%@page import="java.lang.reflect.Field"%> <%--<%@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"%> @@ -15,7 +15,7 @@ <%@page import="org.mxchange.pizzaapplication.beans.CustomerBean" %> <%@page import="org.mxchange.pizzaapplication.product.Product"%> - + <% @@ -36,7 +36,7 @@
@@ -138,10 +138,6 @@ %>
  • <%=entry.getKey().getName()%> set to: <%=entry.getValue()%>
  • <% - // Set it in session - synchronized (session) { - session.setAttribute(entry.getKey().getName(), entry.getValue()); - } } %> diff --git a/web/form_handler/order.jsp b/web/form_handler/order.jsp new file mode 100644 index 00000000..926b2e58 --- /dev/null +++ b/web/form_handler/order.jsp @@ -0,0 +1,71 @@ +<%-- + Document : order + Created on : 07.08.2015, 14:58:21 + 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.beans.CustomerBean" %> +<%@page import="org.mxchange.pizzaapplication.application.PizzaServiceApplication"%> +<%@page import="org.mxchange.pizzaapplication.application.PizzaApplication"%> + + + + +<% + // Init application instance + PizzaApplication app = PizzaServiceApplication.getInstance(application); + + // Is it post? + if ("POST".equals(request.getMethod())) { + // Is POST, so continue with handling + Iterator> fieldIterator = customer.iterator(); + + while (fieldIterator.hasNext()) { + Map.Entry entry = fieldIterator.next(); + + // Debug message + app.getLogger().debug("entry " + entry.getKey() + "=" + entry.getValue()); + + // Set it in session + app.setValueInSession(session, entry.getKey().getName(), entry.getValue()); + } + + // Redirect to proper URL + //response.sendRedirect(request.getContextPath() + "/finished.jsp"); + } +%> + + + + + + + + <%=PizzaServiceApplication.MAIN_TITLE%> - Form-Handler + + + +
    +

    <%=PizzaServiceApplication.MAIN_TITLE%> - Form-Handler

    +
    + + + +
    +
    +

    Bitte nicht direkt aufrufen:

    +
    + +
    + Bitte rufen Sie diese Seite nicht direkt auf. +
    +
    + + diff --git a/web/index.jsp b/web/index.jsp index d2c0ea7f..d293fa26 100644 --- a/web/index.jsp +++ b/web/index.jsp @@ -30,7 +30,7 @@
    @@ -39,7 +39,7 @@
    -
    + diff --git a/web/order.jsp b/web/order.jsp deleted file mode 100644 index 35d6ec23..00000000 --- a/web/order.jsp +++ /dev/null @@ -1,274 +0,0 @@ -<%-- - Document : order - Created on : 04.08.2015, 10:55:10 - Author : Roland Haeder ---%> - -<%--<%@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 - - - -
    -

    <%=PizzaServiceApplication.MAIN_TITLE%> - Bestellung anzeigen

    -
    - - - -
    -
    -

    Folgendes möchten Sie bestellen:

    -
    - -
    - -
    - - - - - - - - - - - <% - // Get iterator from products - Iterator> iterator = app.getProductsIterator(); - - // Iterate over all - while (iterator.hasNext()) { - // Get entry - Map.Entry entry = iterator.next(); - - // Get product - Product product = entry.getValue(); - %> - - - - - - - - <% - // Is it choosen and amount set? - if (app.isProductChoosen(product, request, session)) { - // Then mark it as choosen - product.markAsChoosen(); - app.unmarkProductAsOrdered(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)%> -
    -
    - Bitte Ihre Daten eingeben: - -
    -
    - -
    -
    - -
    -
    -
    - -
    -
    - -
    -
    - " <%=app.getDisabledHtmlFromSession(request, session)%> /> -
    -
    -
    - -
    -
    - -
    -
    - " <%=app.getDisabledHtmlFromSession(request, session)%> /> -
    -
    -
    - -
    -
    - -
    -
    - " <%=app.getDisabledHtmlFromSession(request, session)%> /> -
    -
    -
    - -
    -
    - -
    -
    - " <%=app.getDisabledHtmlFromSession(request, session)%> /> -
    -
    -
    - -
    -
    - -
    -
    - " <%=app.getDisabledHtmlFromSession(request, session)%> /> -
    -
    -
    - -
    -
    - -
    -
    - " <%=app.getDisabledHtmlFromSession(request, session)%> /> -
    -
    -
    - -
    -
    - -
    -
    - " <%=app.getDisabledHtmlFromSession(request, session)%> /> -
    -
    -
    - -
    -
    - -
    -
    - " <%=app.getDisabledHtmlFromSession(request, session)%> /> -
    -
    -
    - -
    -
    - -
    -
    - " <%=app.getDisabledHtmlFromSession(request, session)%> /> -
    -
    -
    - -
    -
    - -
    -
    - " <%=app.getDisabledHtmlFromSession(request, session)%> /> -
    -
    -
    -
    -
    -
    -
    - - - diff --git a/web/preview.jsp b/web/preview.jsp new file mode 100644 index 00000000..afebc535 --- /dev/null +++ b/web/preview.jsp @@ -0,0 +1,274 @@ +<%-- + Document : order + Created on : 04.08.2015, 10:55:10 + Author : Roland Haeder +--%> + +<%--<%@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 + + + +
    +

    <%=PizzaServiceApplication.MAIN_TITLE%> - Bestellung anzeigen

    +
    + + + +
    +
    +

    Folgendes möchten Sie bestellen:

    +
    + +
    +
    + + + + + + + + + + + + <% + // Get iterator from products + Iterator> iterator = app.getProductsIterator(); + + // Iterate over all + while (iterator.hasNext()) { + // Get entry + Map.Entry entry = iterator.next(); + + // Get product + Product product = entry.getValue(); + %> + + + + + + + + <% + // Is it choosen and amount set? + if (app.isProductChoosen(product, request, session)) { + // Then mark it as choosen + product.markAsChoosen(); + app.unmarkProductAsOrdered(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)%> +
    +
    + Bitte Ihre Daten eingeben: + +
    +
    + +
    +
    + +
    +
    +
    + +
    +
    + +
    +
    + " <%=app.getDisabledHtmlFromSession(request, session)%> /> +
    +
    +
    + +
    +
    + +
    +
    + " <%=app.getDisabledHtmlFromSession(request, session)%> /> +
    +
    +
    + +
    +
    + +
    +
    + " <%=app.getDisabledHtmlFromSession(request, session)%> /> +
    +
    +
    + +
    +
    + +
    +
    + " <%=app.getDisabledHtmlFromSession(request, session)%> /> +
    +
    +
    + +
    +
    + +
    +
    + " <%=app.getDisabledHtmlFromSession(request, session)%> /> +
    +
    +
    + +
    +
    + +
    +
    + " <%=app.getDisabledHtmlFromSession(request, session)%> /> +
    +
    +
    + +
    +
    + +
    +
    + " <%=app.getDisabledHtmlFromSession(request, session)%> /> +
    +
    +
    + +
    +
    + +
    +
    + " <%=app.getDisabledHtmlFromSession(request, session)%> /> +
    +
    +
    + +
    +
    + +
    +
    + " <%=app.getDisabledHtmlFromSession(request, session)%> /> +
    +
    +
    + +
    +
    + +
    +
    + " <%=app.getDisabledHtmlFromSession(request, session)%> /> +
    +
    +
    +
    +
    +
    +
    +
    + + diff --git a/web/static/menu.jsp b/web/static/menu.jsp index 9459812e..8136267b 100644 --- a/web/static/menu.jsp +++ b/web/static/menu.jsp @@ -6,7 +6,7 @@