From: Roland Haeder Date: Tue, 1 Sep 2015 12:17:28 +0000 (+0200) Subject: Get the basket bean directly from session scope X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=4fe82c47c26af51851c7b0079b8c5798ca633e8d;p=pizzaservice-war.git Get the basket bean directly from session scope Signed-off-by:Roland Häder --- diff --git a/src/java/org/mxchange/pizzaapplication/filter/servlet/basket/BasketItemAddedFilter.java b/src/java/org/mxchange/pizzaapplication/filter/servlet/basket/BasketItemAddedFilter.java index 6de8edc8..66089c88 100644 --- a/src/java/org/mxchange/pizzaapplication/filter/servlet/basket/BasketItemAddedFilter.java +++ b/src/java/org/mxchange/pizzaapplication/filter/servlet/basket/BasketItemAddedFilter.java @@ -32,7 +32,6 @@ import org.mxchange.jcore.exceptions.BadTokenException; import org.mxchange.jcore.exceptions.CorruptedDatabaseFileException; import org.mxchange.jshop.beans.basket.BasketBean; import org.mxchange.jshop.item.AddableBasketItem; -import org.mxchange.pizzaapplication.beans.controller.PizzaBean; import org.mxchange.pizzaapplication.filter.servlet.BaseServletFilter; /** @@ -72,10 +71,10 @@ public class BasketItemAddedFilter extends BaseServletFilter implements Filter { // item should not be null if (null == object) { // item is null - throw new NullPointerException("item is null"); //NOI18N + throw new NullPointerException("object is null"); //NOI18N } else if (!(object instanceof AddableBasketItem)) { // Not right instance - throw new IllegalArgumentException("item does not implement AddableBasketItem"); //NOI18N + throw new IllegalArgumentException("object does not implement AddableBasketItem"); //NOI18N } // Now it is secure to cast @@ -100,14 +99,8 @@ public class BasketItemAddedFilter extends BaseServletFilter implements Filter { throw new NullPointerException("session is null"); //NOI18N } - // Get man controller - PizzaBean bean = (PizzaBean) session.getAttribute("controller"); //NOI18N - - // Debug message - this.getLogger().debug(MessageFormat.format("bean={0}", bean)); //NOI18N - // Get basket instance - BasketBean basket = bean.getBasket(); + BasketBean basket = (BasketBean) session.getAttribute("basket"); //NOI18N // Debug message this.getLogger().debug(MessageFormat.format("basket={0}", basket)); //NOI18N @@ -133,14 +126,14 @@ public class BasketItemAddedFilter extends BaseServletFilter implements Filter { // Register item with it basket.addItem(item); - // Is amount null or zero? - if ((item.getAmount() == null) || (item.getAmount() == 0)) { - // Then redirect to added=0 - ((HttpServletResponse) response).sendRedirect(servletRequest.getContextPath() + "/?add=0"); //NOI18N - } else { - // Redirect to proper URL - ((HttpServletResponse) response).sendRedirect(servletRequest.getContextPath() + "/?add=1"); //NOI18N - } + // Is amount null or zero? + if ((item.getAmount() == null) || (item.getAmount() == 0)) { + // Then redirect to added=0 + ((HttpServletResponse) response).sendRedirect(servletRequest.getContextPath() + "/?add=0"); //NOI18N + } else { + // Redirect to proper URL + ((HttpServletResponse) response).sendRedirect(servletRequest.getContextPath() + "/?add=1"); //NOI18N + } } catch (final SQLException | BadTokenException | CorruptedDatabaseFileException | NoSuchMethodException | IllegalAccessException | InvocationTargetException ex) { // Continue to throw throw new ServletException(ex);