import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
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;
/**
// 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
// Debug message
this.getLogger().debug(MessageFormat.format("item.id={0},item.itemId={1},item.itemType={2},item.amount={3}", item.getId(), item.getItemId(), item.getItemType(), item.getAmount())); //NOI18N
- // Init instance
- BasketBean basket;
try {
+ // Cast to servlet request
+ HttpServletRequest servletRequest = (HttpServletRequest) request;
+
// Get session instance
- HttpSession session = ((HttpServletRequest) request).getSession();
+ HttpSession session = servletRequest.getSession();
// Debug message
this.getLogger().debug(MessageFormat.format("session={0}", session)); //NOI18N
throw new NullPointerException("session is null"); //NOI18N
}
- // Get man controller
- PizzaBean bean = (PizzaBean) session.getAttribute("controller"); //NOI18N
-
- // Debug message
- this.getLogger().debug("bean=" + bean);
-
// Get basket instance
- basket = bean.getBasket();
+ BasketBean basket = (BasketBean) session.getAttribute("basket"); //NOI18N
// Debug message
- this.getLogger().debug("basket=" + basket);
+ this.getLogger().debug(MessageFormat.format("basket={0}", basket)); //NOI18N
// Is the item already added?
if (item.getItemId() == null) {
throw new NullPointerException(MessageFormat.format("item type of item={0} is null", item)); //NOI18N
} else if ((item.getAmount() == null) || (item.getAmount() == 0)) {
// Debug message
- this.getLogger().debug(MessageFormat.format("Amount for item {0} is null", item)); //NOI18N
+ this.getLogger().debug(MessageFormat.format("Amount for item {0} is null - EXIT!", item)); //NOI18N
// Amount is not entered
return;
// 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
+ }
} catch (final SQLException | BadTokenException | CorruptedDatabaseFileException | NoSuchMethodException | IllegalAccessException | InvocationTargetException ex) {
// Continue to throw
throw new ServletException(ex);