* @param session Session instance
*/
public void unmarkProductAsOrdered(final Product product, final HttpSession session);
+
+ /**
+ * Some getter for printable value from session or an empty string for null.
+ *
+ * @param session Session instance
+ * @param key Key to get
+ * @return Value from key, empty string for null
+ */
+ public Object getPrintableValeFromSession (final HttpSession session, final String key);
}
*/
package org.mxchange.pizzaapplication.application;
+import java.lang.reflect.Field;
import java.text.MessageFormat;
import java.util.Iterator;
import java.util.Map;
this.getLogger().trace(MessageFormat.format("product={0},session={1},attribute={2} - CALLED!", product, session, attribute)); //NOI18N
// Init variable
+ Object value = this.getValueFromSession(session, String.format(HTTP_PARAM_MASK, product.getName(), attribute));
+
+ this.getLogger().debug(MessageFormat.format("product={0},attribute={1},value={2}", product.getName(), attribute, value)); //NOI18N
+
+ // Trace message
+ this.getLogger().trace(MessageFormat.format("value={0} - EXIT!", value)); //NOI18N
+
+ // Return it
+ return value;
+ }
+
+ /**
+ * Some getter for value from session
+ *
+ * @param session Session instance
+ * @param key Key to get value from
+ * @return Value from session
+ */
+ private Object getValueFromSession (final HttpSession session, final String key) {
+ // Trace message
+ this.getLogger().trace(MessageFormat.format("session={043},key={1} - CALLED!", session, key)); //NOI18N
+
+ // Init value
Object value = null;
- // Get it synced
+ // Get it synchronized from session
synchronized (session) {
- value = session.getAttribute(String.format(HTTP_PARAM_MASK, product.getName(), attribute));
+ value = session.getAttribute(key);
}
- this.getLogger().debug(MessageFormat.format("product={0},attribute={1},value={2}", product.getName(), attribute, value)); //NOI18N
-
// Trace message
this.getLogger().trace(MessageFormat.format("value={0} - EXIT!", value)); //NOI18N
Customer customer = new PizzaServiceCustomer();
/*
- * Need a least a gender :( See, that is why I don't like default
+ * Need a least a gender ... :( See, that is why I don't like default
* constructors, you can easily miss something important and bam! You
* get an NPE. The fix here is, to have construtors (or factories) which
* requires all required instances that needs to be set to get a
customer.setGender(Gender.MALE);
// Get iterator on all its fields
- Iterator<Object> it = customer.iterator();
+ Iterator<Map.Entry<Field, Object>> it = customer.iterator();
// Output it
while (it.hasNext()) {
- Object field = it.next();
- this.getLogger().debug("field=" + field);
+ Map.Entry<Field, Object> entry = it.next();
+ this.getLogger().debug(MessageFormat.format("entry {0}={1}", entry.getKey(), entry.getValue()));
}
}
/**
* Some "getter" for amount from session
+ *
* @param product Product instance
* @param session Session instance
* @return Amount as string
// Trace message
this.getLogger().trace("EXIT!"); //NOI18N
}
+
+ /**
+ * Some getter for printable value from session or an empty string for null.
+ *
+ * @param session Session instance
+ * @param key Key to get
+ * @return Value from key, empty string for null
+ */
+ @Override
+ public Object getPrintableValeFromSession (final HttpSession session, final String key) {
+ // Trace message
+ this.getLogger().trace(MessageFormat.format("session={0},key={1} - CALLED", session, key));
+
+ // Are both parameter not null?
+ if (session == null) {
+ // Abort here
+ throw new NullPointerException("session is null");
+ } else if (key == null) {
+ // Abort here
+ throw new NullPointerException("key is null");
+ }
+
+ // Now get it
+ Object value = this.getValueFromSession(session, key);
+
+ // Debug message
+ this.getLogger().debug(MessageFormat.format("value={0}", value));
+
+ // Trace message
+ this.getLogger().trace(MessageFormat.format("Calling this.convertNullToEmpty({0}) ... - EXIT!", value));
+
+ // Return actual value
+ return this.convertNullToEmpty(value);
+ }
}
*
* @author Roland Haeder
*/
-public interface CustomerBean extends Customer, Iterable<Object> {
+public interface CustomerBean extends Customer {
}
*/
package org.mxchange.pizzaapplication.customer.bean;
+import java.lang.reflect.Field;
import java.util.Iterator;
+import java.util.Map;
import org.mxchange.jcore.client.Client;
import org.mxchange.jcore.contact.Contact;
import org.mxchange.jcore.contact.Gender;
}
@Override
- public Iterator<Object> iterator () {
+ public Iterator<Map.Entry<Field, Object>> iterator () {
// Deligate to "hidden" object
return this.getContact().iterator();
}
Author : Roland Haeder
--%>
+<%@page import="java.lang.reflect.Field"%>
<%--<%@page errorPage="errorHandler.jsp" %>--%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<tr>
<td colspan="5" class="table_header">
<%
- Iterator<Object> fieldIterator = customer.iterator();
+ Iterator<Map.Entry<Field, Object>> fieldIterator = customer.iterator();
%>
<ul>
<%
while (fieldIterator.hasNext()) {
- %>
- <li><%=fieldIterator.next()%></li>
- <%
+ Map.Entry<Field, Object> entry = fieldIterator.next();
+ %>
+ <li><%=entry.getKey().getName()%> set to: <%=entry.getValue()%></li>
+ <%
+ // Set it in session
+ synchronized (session) {
+ session.setAttribute(entry.getKey().getName(), entry.getValue());
+ }
}
%>
</ul>
out.print("Ihre Bestellung ist eingegangen.");
synchronized(session) {
//session.invalidate();
+ out.print("<div>Zu Demo-Zwecken wird die Sitzung nicht gekillt. Bitte 'Bestellung' aufrufen, um zu gucken, dass die Daten da sind.</div>");
}
} else {
// Nothing ordered
Gender[] genders = Gender.values();
for (final Gender gender : genders) {
%>
- <option value="<%=gender.name()%>"><%=gender%></option>
+ <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\"");
+ }
+ }
+ %>><%=gender%></option>
<%
}
- %>
+ %>
</select>
</div>
<div class="clear"></div>
<label for="companyname">Firmenname:</label>
</div>
<div class="data_right">
- <input type="text" id="companyname" name="companyname" size="10" maxlength="255" <%=app.getDisabledHtmlFromSession(request, session)%> />
+ <input type="text" id="companyname" name="companyname" size="10" maxlength="255" value="<%=app.getPrintableValeFromSession(session, "companyname")%>" <%=app.getDisabledHtmlFromSession(request, session)%> />
</div>
<div class="clear"></div>
</div>
<label for="surname">Vorname:</label>
</div>
<div class="data_right">
- <input type="text" id="surname" name="surname" size="10" maxlength="255" <%=app.getDisabledHtmlFromSession(request, session)%> />
+ <input type="text" id="surname" name="surname" size="10" maxlength="255" value="<%=app.getPrintableValeFromSession(session, "surname")%>" <%=app.getDisabledHtmlFromSession(request, session)%> />
</div>
<div class="clear"></div>
</div>
<label for="familyname">Nachname:</label>
</div>
<div class="data_right">
- <input type="text" id="familyname" name="familyname" size="10" maxlength="255" <%=app.getDisabledHtmlFromSession(request, session)%> />
+ <input type="text" id="familyname" name="familyname" size="10" maxlength="255" value="<%=app.getPrintableValeFromSession(session, "familyname")%>" <%=app.getDisabledHtmlFromSession(request, session)%> />
</div>
<div class="clear"></div>
</div>
<label for="street">Straße:</label>
</div>
<div class="data_right">
- <input type="text" id="street" name="street" size="20" maxlength="255" <%=app.getDisabledHtmlFromSession(request, session)%> />
+ <input type="text" id="street" name="street" size="20" maxlength="255" value="<%=app.getPrintableValeFromSession(session, "street")%>" <%=app.getDisabledHtmlFromSession(request, session)%> />
</div>
<div class="clear"></div>
</div>
<label for="houseNumber">Hausnummer:</label>
</div>
<div class="data_right">
- <input type="text" id="houseNumber" name="houseNumber" size="3" maxlength="5" <%=app.getDisabledHtmlFromSession(request, session)%> />
+ <input type="text" id="houseNumber" name="houseNumber" size="3" maxlength="5" value="<%=app.getPrintableValeFromSession(session, "houseNumber")%>" <%=app.getDisabledHtmlFromSession(request, session)%> />
</div>
<div class="clear"></div>
</div>
<label for="zipCode">Postleitzahl:</label>
</div>
<div class="data_right">
- <input type="text" id="zipCode" name="zipCode" size="5" maxlength="6" <%=app.getDisabledHtmlFromSession(request, session)%> />
+ <input type="text" id="zipCode" name="zipCode" size="5" maxlength="6" value="<%=app.getPrintableValeFromSession(session, "zipCode")%>" <%=app.getDisabledHtmlFromSession(request, session)%> />
</div>
<div class="clear"></div>
</div>
<label for="city">Ort:</label>
</div>
<div class="data_right">
- <input type="text" id="city" name="city" size="10" maxlength="255" <%=app.getDisabledHtmlFromSession(request, session)%> />
+ <input type="text" id="city" name="city" size="10" maxlength="255" value="<%=app.getPrintableValeFromSession(session, "city")%>" <%=app.getDisabledHtmlFromSession(request, session)%> />
</div>
<div class="clear"></div>
</div>
<label for="phoneNumber">Telefon:</label>
</div>
<div class="data_right">
- <input type="text" id="phoneNumber" name="phoneNumber" size="20" maxlength="255" <%=app.getDisabledHtmlFromSession(request, session)%> />
+ <input type="text" id="phoneNumber" name="phoneNumber" size="20" maxlength="255" value="<%=app.getPrintableValeFromSession(session, "phoneNumber")%>" <%=app.getDisabledHtmlFromSession(request, session)%> />
</div>
<div class="clear"></div>
</div>
<label for="faxNumber">Faxnummer:</label>
</div>
<div class="data_right">
- <input type="text" id="faxNumber" name="faxNumber" size="20" maxlength="255" <%=app.getDisabledHtmlFromSession(request, session)%> />
+ <input type="text" id="faxNumber" name="faxNumber" size="20" maxlength="255" value="<%=app.getPrintableValeFromSession(session, "faxNumber")%>" <%=app.getDisabledHtmlFromSession(request, session)%> />
</div>
<div class="clear"></div>
</div>
<label for="cellphoneNumber">Handy:</label>
</div>
<div class="data_right">
- <input type="text" id="cellphoneNumber" name="cellphoneNumber" size="20" maxlength="255" <%=app.getDisabledHtmlFromSession(request, session)%> />
+ <input type="text" id="cellphoneNumber" name="cellphoneNumber" size="20" maxlength="255" value="<%=app.getPrintableValeFromSession(session, "cellphoneNumber")%>" <%=app.getDisabledHtmlFromSession(request, session)%> />
</div>
<div class="clear"></div>
</div>