]> git.mxchange.org Git - pizzaservice-war.git/commitdiff
Continued with project:
authorRoland Haeder <roland@mxchange.org>
Mon, 10 Aug 2015 13:16:45 +0000 (15:16 +0200)
committerRoland Haeder <roland@mxchange.org>
Mon, 10 Aug 2015 13:16:45 +0000 (15:16 +0200)
- 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 <roland@mxchange.org>

src/java/org/mxchange/pizzaapplication/application/PizzaServiceApplication.java
src/java/org/mxchange/pizzaapplication/customer/bean/PizzaServiceCustomerBean.java
web/finished.jsp
web/form_handler/order.jsp
web/preview.jsp

index 163075e5f5d14f24b917930aefeabcbd05bd9f25..df6cf19228334e3215c3d6b2a9967d6373381824 100644 (file)
@@ -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
index 3b7de4c2f73375a8ba428aec4bca92a50fdf6eb4..dcb94724f3133efa4a2df344488a3af5d32f0c92 100644 (file)
@@ -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);
        }
index 0339ebe6fe411ceab238b53a140da7c4d496439d..2ad0f23ac7cdae8edad7f42615ef22ea9ecfd1a6 100644 (file)
                                                <tr>
                                                        <td colspan="5" class="table_row">
                                                                <%
+                                                               // Debug message
+                                                               app.getLogger().debug("customer=" + customer);
+
+                                                               // Get iterator on all fields/attributes
                                                                Iterator<Map.Entry<Field, Object>> fieldIterator = customer.iterator();
                                                                %>
                                                                <ul>
index 55539f0209bf5cde6e148938191a885c24117bec..6ddf7e7c12042268d499eb8ef6281c15b85538c5 100644 (file)
@@ -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"%>
 
-<jsp:useBean id="customer" scope="request" class="org.mxchange.pizzaapplication.customer.bean.PizzaServiceCustomerBean" type="CustomerBean" />
-<jsp:setProperty name="customer" property="*" />
-
 <%
        // Init application instance
        PizzaApplication app = PizzaServiceApplication.getInstance(application);
 
        // Is it post?
        if ("POST".equals(request.getMethod())) { //NOI18N
-               // Is POST, so continue with handling
-               Iterator<Map.Entry<Field, Object>> fieldIterator = customer.iterator();
-
-               while (fieldIterator.hasNext()) {
-                       // Get next field
-                       Map.Entry<Field, Object> 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");
-       }
 %>
+<jsp:useBean id="customer" scope="session" class="org.mxchange.pizzaapplication.customer.bean.PizzaServiceCustomerBean" type="CustomerBean" />
+<jsp:setProperty name="customer" property="*" />
 <jsp:forward page="../finished.jsp" />
+<%
+       }
+%>
 
 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="de" lang="de">
index 70fb334a0cbd3eedecf8fc87db9c13f1066ada29..22f8e7e879c954013c0630404f509b3e939c564c 100644 (file)
@@ -15,7 +15,6 @@
 <%@page contentType="text/html" pageEncoding="UTF-8"%>
 
 <jsp:useBean id="customer" scope="session" class="org.mxchange.pizzaapplication.customer.bean.PizzaServiceCustomerBean" type="CustomerBean" />
-
 <jsp:setProperty name="customer" property="*" />
 
 <%
                                                                                <div class="data_left">
                                                                                        <label for="gender">Anrede</label>
                                                                                </div>
+
                                                                                <div class="data_right">
-                                                                                       <select name="gender" id="gender" size="1">
+                                                                                       <select name="gender" id="gender" size="1" <%=app.getDisabledHtmlFromSession(request, session)%>>
                                                                                                <%
-                                                                                               Gender[] genders = Gender.values();
-                                                                                               for (final Gender gender : genders) {
+                                                                                               // "Walk" through all genders and output them
+                                                                                               for (final Gender gender : Gender.values()) {
                                                                                                        %>
                                                                                                        <option value="<%=gender.name()%>"<%
-                                                                                                       synchronized (session) {
-                                                                                                               // Get session value
-                                                                                                               Object value = session.getAttribute("gender");
-                                                                                                               if ((value instanceof Gender) && (value.equals(gender))) {
-                                                                                                                       // Output selected="selected"
-                                                                                                                       out.print("selected=\"selected\"");
-                                                                                                               }
+                                                                                                       // Get gender from bean
+                                                                                                       Gender value=  customer.getGender();
+
+                                                                                                       // Test it
+                                                                                                       if (value.equals(gender)) {
+                                                                                                               // Output selected="selected"
+                                                                                                               out.print("selected=\"selected\"");
                                                                                                        }
                                                                                                        %>><%=gender%></option>
                                                                                                        <%
                                                                                                %> 
                                                                                        </select>
                                                                                </div>
-                                                                               <div class="clear"></div>
+
+                                                                                       <div class="clear"></div>
                                                                        </div>
 
                                                                        <div class="data_row">
                                                                                <div class="data_left">
                                                                                        <label for="companyname">Firmenname:</label>
                                                                                </div>
+
                                                                                <div class="data_right">
-                                                                                       <input type="text" id="companyname" name="companyName" size="10" maxlength="255" value="<%=app.getPrintableValeFromSession(session, "companyname")%>" <%=app.getDisabledHtmlFromSession(request, session)%> />
+                                                                                       <input type="text" id="companyname" name="companyName" size="15" maxlength="255" value="${customer.companyName}" <%=app.getDisabledHtmlFromSession(request, session)%> />
                                                                                </div>
+
                                                                                <div class="clear"></div>
                                                                        </div>
 
                                                                                <div class="data_left">
                                                                                        <label for="surname">Vorname:</label>
                                                                                </div>
+
                                                                                <div class="data_right">
-                                                                                       <input type="text" id="surname" name="surname" size="10" maxlength="255" value="<%=app.getPrintableValeFromSession(session, "surname")%>" <%=app.getDisabledHtmlFromSession(request, session)%> />
+                                                                                       <input type="text" id="surname" name="surname" size="10" maxlength="255" value="${customer.surname}" <%=app.getDisabledHtmlFromSession(request, session)%> />
                                                                                </div>
+
                                                                                <div class="clear"></div>
                                                                        </div>
 
                                                                                <div class="data_left">
                                                                                        <label for="familyName">Nachname:</label>
                                                                                </div>
+
                                                                                <div class="data_right">
-                                                                                       <input type="text" id="familyName" name="familyName" size="10" maxlength="255" value="<%=app.getPrintableValeFromSession(session, "familyName")%>" <%=app.getDisabledHtmlFromSession(request, session)%> />
+                                                                                       <input type="text" id="familyName" name="familyName" size="10" maxlength="255" value="${customer.familyName}" <%=app.getDisabledHtmlFromSession(request, session)%> />
                                                                                </div>
+
                                                                                <div class="clear"></div>
                                                                        </div>
 
                                                                                <div class="data_left">
                                                                                        <label for="street">Straße:</label>
                                                                                </div>
+
                                                                                <div class="data_right">
-                                                                                       <input type="text" id="street" name="street" size="20" maxlength="255" value="<%=app.getPrintableValeFromSession(session, "street")%>" <%=app.getDisabledHtmlFromSession(request, session)%> />
+                                                                                       <input type="text" id="street" name="street" size="20" maxlength="255" value="${customer.street}" <%=app.getDisabledHtmlFromSession(request, session)%> />
                                                                                </div>
+
                                                                                <div class="clear"></div>
                                                                        </div>
 
                                                                                <div class="data_left">
                                                                                        <label for="houseNumber">Hausnummer:</label>
                                                                                </div>
+
                                                                                <div class="data_right">
-                                                                                       <input type="text" id="houseNumber" name="houseNumber" size="3" maxlength="5" value="<%=app.getPrintableValeFromSession(session, "houseNumber")%>" <%=app.getDisabledHtmlFromSession(request, session)%> />
+                                                                                       <input type="text" id="houseNumber" name="houseNumber" size="3" maxlength="5" value="${customer.houseNumber}" <%=app.getDisabledHtmlFromSession(request, session)%> />
                                                                                </div>
+
                                                                                <div class="clear"></div>
                                                                        </div>
 
                                                                                <div class="data_left">
                                                                                        <label for="zipCode">Postleitzahl:</label>
                                                                                </div>
+
                                                                                <div class="data_right">
-                                                                                       <input type="text" id="zipCode" name="zipCode" size="5" maxlength="6" value="<%=app.getPrintableValeFromSession(session, "zipCode")%>" <%=app.getDisabledHtmlFromSession(request, session)%> />
+                                                                                       <input type="text" id="zipCode" name="zipCode" size="5" maxlength="6" value="${customer.zipCode}" <%=app.getDisabledHtmlFromSession(request, session)%> />
                                                                                </div>
+
                                                                                <div class="clear"></div>
                                                                        </div>
 
                                                                                <div class="data_left">
                                                                                        <label for="city">Ort:</label>
                                                                                </div>
+
                                                                                <div class="data_right">
-                                                                                       <input type="text" id="city" name="city" size="10" maxlength="255" value="<%=app.getPrintableValeFromSession(session, "city")%>" <%=app.getDisabledHtmlFromSession(request, session)%> />
+                                                                                       <input type="text" id="city" name="city" size="10" maxlength="255" value="${customer.city}" <%=app.getDisabledHtmlFromSession(request, session)%> />
                                                                                </div>
+
                                                                                <div class="clear"></div>
                                                                        </div>
 
                                                                                <div class="data_left">
                                                                                        <label for="phoneNumber">Telefon:</label>
                                                                                </div>
+
                                                                                <div class="data_right">
-                                                                                       <input type="text" id="phoneNumber" name="phoneNumber" size="20" maxlength="255" value="<%=app.getPrintableValeFromSession(session, "phoneNumber")%>" <%=app.getDisabledHtmlFromSession(request, session)%> />
+                                                                                       <input type="text" id="phoneNumber" name="phoneNumber" size="20" maxlength="255" value="${customer.phoneNumber}" <%=app.getDisabledHtmlFromSession(request, session)%> />
                                                                                </div>
+
                                                                                <div class="clear"></div>
                                                                        </div>
 
                                                                                <div class="data_left">
                                                                                        <label for="faxNumber">Faxnummer:</label>
                                                                                </div>
+
                                                                                <div class="data_right">
-                                                                                       <input type="text" id="faxNumber" name="faxNumber" size="20" maxlength="255" value="<%=app.getPrintableValeFromSession(session, "faxNumber")%>" <%=app.getDisabledHtmlFromSession(request, session)%> />
+                                                                                       <input type="text" id="faxNumber" name="faxNumber" size="20" maxlength="255" value="${customer.faxNumber}" <%=app.getDisabledHtmlFromSession(request, session)%> />
                                                                                </div>
+
                                                                                <div class="clear"></div>
                                                                        </div>
 
                                                                                <div class="data_left">
                                                                                        <label for="cellphoneNumber">Handy:</label>
                                                                                </div>
+
                                                                                <div class="data_right">
-                                                                                       <input type="text" id="cellphoneNumber" name="cellphoneNumber" size="20" maxlength="255" value="<%=app.getPrintableValeFromSession(session, "cellphoneNumber")%>" <%=app.getDisabledHtmlFromSession(request, session)%> />
+                                                                                       <input type="text" id="cellphoneNumber" name="cellphoneNumber" size="20" maxlength="255" value="${customer.cellphoneNumber}" <%=app.getDisabledHtmlFromSession(request, session)%> />
                                                                                </div>
+
                                                                                <div class="clear"></div>
                                                                        </div>
                                                                </fieldset>