From: Roland Haeder Date: Mon, 10 Aug 2015 13:16:45 +0000 (+0200) Subject: Continued with project: X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=8472dd84ba7567e35698d418485daa6f04f4f9ec;p=pizzaservice-war.git Continued with project: - I had a misunderstanding how beans work, so now it is fixed - Always try to write against interfaces and also check against them (instanceof) - Gender can also be taken directly from customer bean - Use customer bean instead of ugly getPrintableValeFromSession() calls - some other improvements Signed-off-by:Roland Häder --- diff --git a/src/java/org/mxchange/pizzaapplication/application/PizzaServiceApplication.java b/src/java/org/mxchange/pizzaapplication/application/PizzaServiceApplication.java index 163075e5..df6cf192 100644 --- a/src/java/org/mxchange/pizzaapplication/application/PizzaServiceApplication.java +++ b/src/java/org/mxchange/pizzaapplication/application/PizzaServiceApplication.java @@ -64,24 +64,24 @@ public class PizzaServiceApplication extends BasePizzaServiceSystem implements P } // Init instance - PizzaServiceApplication instance = null; + PizzaApplication instance = null; - // Get instance from servlet - Object object = application.getAttribute("service"); //NOI18N + // Get instance from servlet application (aka. "application scope") + Object object = application.getAttribute("app"); //NOI18N // Is it set? - if (object instanceof PizzaServiceApplication) { + if (object instanceof PizzaApplication) { // Instance is set, so casting should work - instance = (PizzaServiceApplication) object; + instance = (PizzaApplication) object; } else if (object instanceof Object) { // Not correct instance - throw new ServletException("service is not set correctly"); //NOI18N + throw new ServletException("app is not set correctly"); //NOI18N } else { // "service" is null, so initialize it instance = new PizzaServiceApplication(); // And set it here - application.setAttribute("service", instance); //NOI18N + application.setAttribute("app", instance); //NOI18N } // 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 3b7de4c2..dcb94724 100644 --- a/src/java/org/mxchange/pizzaapplication/customer/bean/PizzaServiceCustomerBean.java +++ b/src/java/org/mxchange/pizzaapplication/customer/bean/PizzaServiceCustomerBean.java @@ -132,12 +132,18 @@ public class PizzaServiceCustomerBean extends BasePizzaServiceSystem implements @Override public String getFamilyName () { + // Trace call + //* NOISY-DEBUG: */ this.getLogger().trace("CALLED!"); + // Deligate to "hidden" object return this.getContact().getFamilyName(); } @Override public void setFamilyName (final String familyName) { + // Trace call + //* NOISY-DEBUG: */ this.getLogger().trace(MessageFormat.format("familyName={0} - CALLED!", familyName)); + // Deligate to "hidden" object this.getContact().setFamilyName(familyName); } diff --git a/web/finished.jsp b/web/finished.jsp index 0339ebe6..2ad0f23a 100644 --- a/web/finished.jsp +++ b/web/finished.jsp @@ -129,6 +129,10 @@ <% + // Debug message + app.getLogger().debug("customer=" + customer); + + // Get iterator on all fields/attributes Iterator> fieldIterator = customer.iterator(); %>
    diff --git a/web/form_handler/order.jsp b/web/form_handler/order.jsp index 55539f02..6ddf7e7c 100644 --- a/web/form_handler/order.jsp +++ b/web/form_handler/order.jsp @@ -6,42 +6,26 @@ <%--<%@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="java.text.MessageFormat"%> <%@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())) { //NOI18N - // Is POST, so continue with handling - Iterator> fieldIterator = customer.iterator(); - - while (fieldIterator.hasNext()) { - // Get next field - Map.Entry entry = fieldIterator.next(); - - // Debug message - app.getLogger().debug(MessageFormat.format("entry {0}={1}", entry.getKey(), entry.getValue())); //NOI18N - - // Set it in session - app.setValueInSession(session, entry.getKey().getName(), entry.getValue()); - } - // Redirect to proper URL + // @TODO Commented out for developing: //response.sendRedirect(request.getContextPath() + "/finished.jsp"); - } %> + + +<% + } +%> diff --git a/web/preview.jsp b/web/preview.jsp index 70fb334a..22f8e7e8 100644 --- a/web/preview.jsp +++ b/web/preview.jsp @@ -15,7 +15,6 @@ <%@page contentType="text/html" pageEncoding="UTF-8"%> - <% @@ -132,20 +131,21 @@
    +
    - > <% - Gender[] genders = Gender.values(); - for (final Gender gender : genders) { + // "Walk" through all genders and output them + for (final Gender gender : Gender.values()) { %> <% @@ -153,16 +153,19 @@ %>
    -
    + +
    +
    - " <%=app.getDisabledHtmlFromSession(request, session)%> /> + />
    +
    @@ -170,9 +173,11 @@
    +
    - " <%=app.getDisabledHtmlFromSession(request, session)%> /> + />
    +
    @@ -180,9 +185,11 @@
    +
    - " <%=app.getDisabledHtmlFromSession(request, session)%> /> + />
    +
    @@ -190,9 +197,11 @@
    +
    - " <%=app.getDisabledHtmlFromSession(request, session)%> /> + />
    +
    @@ -200,9 +209,11 @@
    +
    - " <%=app.getDisabledHtmlFromSession(request, session)%> /> + />
    +
    @@ -210,9 +221,11 @@
    +
    - " <%=app.getDisabledHtmlFromSession(request, session)%> /> + />
    +
    @@ -220,9 +233,11 @@
    +
    - " <%=app.getDisabledHtmlFromSession(request, session)%> /> + />
    +
    @@ -230,9 +245,11 @@
    +
    - " <%=app.getDisabledHtmlFromSession(request, session)%> /> + />
    +
    @@ -240,9 +257,11 @@
    +
    - " <%=app.getDisabledHtmlFromSession(request, session)%> /> + />
    +
    @@ -250,9 +269,11 @@
    +
    - " <%=app.getDisabledHtmlFromSession(request, session)%> /> + />
    +