From 8472dd84ba7567e35698d418485daa6f04f4f9ec Mon Sep 17 00:00:00 2001 From: Roland Haeder Date: Mon, 10 Aug 2015 15:16:45 +0200 Subject: [PATCH] =?utf8?q?Continued=20with=20project:=20-=20I=20had=20a=20?= =?utf8?q?misunderstanding=20how=20beans=20work,=20so=20now=20it=20is=20fi?= =?utf8?q?xed=20-=20Always=20try=20to=20write=20against=20interfaces=20and?= =?utf8?q?=20also=20check=20against=20them=20(instanceof)=20-=20Gender=20c?= =?utf8?q?an=20also=20be=20taken=20directly=20from=20customer=20bean=20-?= =?utf8?q?=20Use=20customer=20bean=20instead=20of=20ugly=20getPrintableVal?= =?utf8?q?eFromSession()=20calls=20-=20some=20other=20improvements=20Signe?= =?utf8?q?d-off-by:Roland=20H=C3=A4der=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../application/PizzaServiceApplication.java | 14 ++-- .../bean/PizzaServiceCustomerBean.java | 6 ++ web/finished.jsp | 4 ++ web/form_handler/order.jsp | 28 ++------ web/preview.jsp | 65 ++++++++++++------- 5 files changed, 66 insertions(+), 51 deletions(-) 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)%> /> + />
    +
    -- 2.39.5