]> git.mxchange.org Git - pizzaservice-war.git/commitdiff
Get the basket bean directly from session scope
authorRoland Haeder <roland@mxchange.org>
Tue, 1 Sep 2015 12:17:28 +0000 (14:17 +0200)
committerRoland Haeder <roland@mxchange.org>
Tue, 1 Sep 2015 12:17:28 +0000 (14:17 +0200)
Signed-off-by:Roland Häder <roland@mxchange.org>

src/java/org/mxchange/pizzaapplication/filter/servlet/basket/BasketItemAddedFilter.java

index 6de8edc808fc2ba346aaeaa27c857a7c5081e805..66089c88c7a743bcc878954ad92cdbd7bad04f41 100644 (file)
@@ -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);