From 46ed5739fee5853054618771d5c9cdcb07e355ff Mon Sep 17 00:00:00 2001 From: Roland Haeder Date: Fri, 7 Aug 2015 15:49:41 +0200 Subject: [PATCH] =?utf8?q?Introduced=20setValueInSession()=20+=20order.jsp?= =?utf8?q?=20form=20handler=20(broken,=20why=3F)=20Signed-off-by:Roland=20?= =?utf8?q?H=C3=A4der=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../application/PizzaApplication.java | 9 +++ .../application/PizzaServiceApplication.java | 25 ++++++- .../bean/PizzaServiceCustomerBean.java | 11 +-- web/bye.jsp | 2 +- web/errorHandler.jsp | 6 +- web/finished.jsp | 10 +-- web/form_handler/order.jsp | 71 +++++++++++++++++++ web/index.jsp | 4 +- web/{order.jsp => preview.jsp} | 4 +- web/static/menu.jsp | 2 +- 10 files changed, 123 insertions(+), 21 deletions(-) create mode 100644 web/form_handler/order.jsp rename web/{order.jsp => preview.jsp} (98%) 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/preview.jsp similarity index 98% rename from web/order.jsp rename to web/preview.jsp index 35d6ec23..afebc535 100644 --- a/web/order.jsp +++ b/web/preview.jsp @@ -36,7 +36,7 @@
    @@ -45,7 +45,7 @@
    - +
    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 @@ -- 2.39.5