From: Roland Haeder Date: Mon, 31 Aug 2015 13:13:05 +0000 (+0200) Subject: Continued with project: X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=5274d656ce0be29e2c3cf3b5d6f56099dd5a2e2a;p=pizzaservice-war.git Continued with project: - Cleaned up duplicated defined methods in interface - Used ServletRequest and ServletResponse instead of Http varriants (casting was required) - Got rid of 2 parameters for doAdminHandleFooForms() methods - Got rid of HttpServletRequest/-Response interfaces, used Http-less varriant - No need to set basket in admin category.jsp - updated jshop.jar Signed-off-by:Roland Häder --- diff --git a/lib/jshop.jar b/lib/jshop.jar index 4a388d8a..ddd7f0d3 100644 Binary files a/lib/jshop.jar and b/lib/jshop.jar differ diff --git a/src/java/org/mxchange/pizzaapplication/application/PizzaApplication.java b/src/java/org/mxchange/pizzaapplication/application/PizzaApplication.java index ffae7095..051ddcd9 100644 --- a/src/java/org/mxchange/pizzaapplication/application/PizzaApplication.java +++ b/src/java/org/mxchange/pizzaapplication/application/PizzaApplication.java @@ -21,8 +21,8 @@ import java.sql.SQLException; import java.util.Iterator; import javax.servlet.ServletContext; import javax.servlet.ServletException; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; +import javax.servlet.ServletRequest; +import javax.servlet.ServletResponse; import javax.servlet.http.HttpSession; import org.mxchange.jcore.application.Application; import org.mxchange.jcore.exceptions.BadTokenException; @@ -71,7 +71,7 @@ public interface PizzaApplication extends Application { * @param session Session instance * @return Whether the product is choosen */ - public String getCheckedHtmlFromProduct (final Product product, final HttpServletRequest request, final HttpSession session); + public String getCheckedHtmlFromProduct (final Product product, final ServletRequest request, final HttpSession session); /** * Some "getter" for HTML code 'disabled="disabled"' for e.g. submit buttons @@ -81,7 +81,7 @@ public interface PizzaApplication extends Application { * @return Whether the product is choosen * @throws javax.servlet.ServletException If something unexpected happened */ - public String getDisabledHtmlFromSession (final HttpServletRequest request, final HttpSession session) throws ServletException; + public String getDisabledHtmlFromSession (final ServletRequest request, final HttpSession session) throws ServletException; /** * Somewhat setter in session @@ -141,7 +141,7 @@ public interface PizzaApplication extends Application { * @throws javax.servlet.ServletException If something unexpected happened * @throws org.mxchange.jshop.exceptions.CategoryTitleAlreadyUsedException If the given title is already used */ - public void doAdminAddCategory (final HttpServletRequest request) throws ServletException, CategoryTitleAlreadyUsedException; + public void doAdminAddCategory (final ServletRequest request) throws ServletException, CategoryTitleAlreadyUsedException; /** * Adds given product data from request to database @@ -150,7 +150,7 @@ public interface PizzaApplication extends Application { * @throws javax.servlet.ServletException If something unexpected happened * @throws org.mxchange.jshop.exceptions.ProductTitleAlreadyUsedException If the given product title is already used */ - public void doAdminAddProduct (final HttpServletRequest request) throws ServletException, ProductTitleAlreadyUsedException; + public void doAdminAddProduct (final ServletRequest request) throws ServletException, ProductTitleAlreadyUsedException; /** * Generates link HTML code for given category's parent id, if set. This @@ -168,7 +168,7 @@ public interface PizzaApplication extends Application { * @param response Response instance * @throws ServletException If something unexpected happened */ - public void doAdminHandleProductForms (final HttpServletRequest request, final HttpServletResponse response) throws ServletException; + public void doAdminHandleProductForms (final ServletRequest request, final ServletResponse response) throws ServletException; /** * Handles admin category form requests @@ -177,7 +177,7 @@ public interface PizzaApplication extends Application { * @param response Response instance * @throws ServletException If something unexpected happened */ - public void doAdminHandleCategoryForms (final HttpServletRequest request, final HttpServletResponse response) throws ServletException; + public void doAdminHandleCategoryForms (final ServletRequest request, final ServletResponse response) throws ServletException; /** * Some "getter" for a Product instance from given item diff --git a/src/java/org/mxchange/pizzaapplication/application/PizzaServiceApplication.java b/src/java/org/mxchange/pizzaapplication/application/PizzaServiceApplication.java index 3e57bf39..a5e35eb3 100644 --- a/src/java/org/mxchange/pizzaapplication/application/PizzaServiceApplication.java +++ b/src/java/org/mxchange/pizzaapplication/application/PizzaServiceApplication.java @@ -24,6 +24,8 @@ import java.text.MessageFormat; import java.util.Iterator; import javax.servlet.ServletContext; import javax.servlet.ServletException; +import javax.servlet.ServletRequest; +import javax.servlet.ServletResponse; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpSession; @@ -102,7 +104,7 @@ public class PizzaServiceApplication extends BasePizzaServiceSystem implements P * @deprecated Old lost */ @Deprecated - private int calculateTotalAmount (final HttpServletRequest request, final HttpSession session) throws ServletException { + private int calculateTotalAmount (final ServletRequest request, final HttpSession session) throws ServletException { // Trace message this.getLogger().trace(MessageFormat.format("request={0},session={1} - CALLED!", request, session)); //NOI18N @@ -203,7 +205,7 @@ public class PizzaServiceApplication extends BasePizzaServiceSystem implements P } @Override - public String getCheckedHtmlFromProduct (final Product product, final HttpServletRequest request, final HttpSession session) { + public String getCheckedHtmlFromProduct (final Product product, final ServletRequest request, final HttpSession session) { // Trace message this.getLogger().trace(MessageFormat.format("product={0},request={1},session={2} - CALLED!", product, request, session)); //NOI18N @@ -236,7 +238,7 @@ public class PizzaServiceApplication extends BasePizzaServiceSystem implements P } @Override - public String getDisabledHtmlFromSession (final HttpServletRequest request, final HttpSession session) throws ServletException { + public String getDisabledHtmlFromSession (final ServletRequest request, final HttpSession session) throws ServletException { // Trace message this.getLogger().trace(MessageFormat.format("request={0},session={1} - CALLED!", request, session)); //NOI18N @@ -347,7 +349,7 @@ public class PizzaServiceApplication extends BasePizzaServiceSystem implements P } @Deprecated - private boolean isProductChoosen (final Product product, final HttpServletRequest request, final HttpSession session) { + private boolean isProductChoosen (final Product product, final ServletRequest request, final HttpSession session) { throw new UnsupportedOperationException("This method is deprecated and shall not be called"); //NOI18N } @@ -468,7 +470,7 @@ public class PizzaServiceApplication extends BasePizzaServiceSystem implements P } @Override - public void doAdminAddCategory (final HttpServletRequest request) throws ServletException, CategoryTitleAlreadyUsedException { + public void doAdminAddCategory (final ServletRequest request) throws ServletException, CategoryTitleAlreadyUsedException { // Trace message this.getLogger().trace(MessageFormat.format("request={0} - CALLED!", request)); //NOI18N @@ -528,7 +530,7 @@ public class PizzaServiceApplication extends BasePizzaServiceSystem implements P } @Override - public void doAdminAddProduct (final HttpServletRequest request) throws ServletException, ProductTitleAlreadyUsedException { + public void doAdminAddProduct (final ServletRequest request) throws ServletException, ProductTitleAlreadyUsedException { // Trace message this.getLogger().trace(MessageFormat.format("request={0} - CALLED!", request)); //NOI18N @@ -693,7 +695,7 @@ public class PizzaServiceApplication extends BasePizzaServiceSystem implements P * @throws java.lang.IllegalAccessException If the method cannot be accessed * @throws java.lang.reflect.InvocationTargetException Any other problems? */ - private boolean isProductTitleUsed (final HttpServletRequest request) throws IOException, SQLException, BadTokenException, CorruptedDatabaseFileException, NoSuchMethodException, IllegalAccessException, IllegalArgumentException, InvocationTargetException { + private boolean isProductTitleUsed (final ServletRequest request) throws IOException, SQLException, BadTokenException, CorruptedDatabaseFileException, NoSuchMethodException, IllegalAccessException, IllegalArgumentException, InvocationTargetException { // Trace message this.getLogger().trace(MessageFormat.format("request={0} - CALLED!", request)); //NOI18N @@ -723,7 +725,7 @@ public class PizzaServiceApplication extends BasePizzaServiceSystem implements P } @Override - public void doAdminHandleProductForms (final HttpServletRequest request, final HttpServletResponse response) throws ServletException { + public void doAdminHandleProductForms (final ServletRequest request, final ServletResponse response) throws ServletException { // Trace message this.getLogger().trace(MessageFormat.format("request={0},response={1} - CALLED!", request, response)); //NOI18N @@ -739,7 +741,7 @@ public class PizzaServiceApplication extends BasePizzaServiceSystem implements P // Try this operations try { // Is it post? - if ("POST".equals(request.getMethod())) { //NOI18N + if ("POST".equals(((HttpServletRequest) request).getMethod())) { //NOI18N // Is "add/edit/delete" set? if (request.getParameter("add") != null) { //NOI18N // Is it already added? @@ -748,13 +750,13 @@ public class PizzaServiceApplication extends BasePizzaServiceSystem implements P this.getLogger().debug("Already used, redirecting ..."); //NOI18N // Already added, so redirect here, else a ServletException will be thrown - response.sendRedirect(String.format("%s/admin/product.jsp?already=1", request.getContextPath())); //NOI18N + ((HttpServletResponse) response).sendRedirect(String.format("%s/admin/product.jsp?already=1", ((HttpServletRequest) request).getContextPath())); //NOI18N } else { // Add new product this.doAdminAddProduct(request); // Redirect to proper URL - response.sendRedirect(String.format("%s/admin/product.jsp?added=1", request.getContextPath())); //NOI18N + ((HttpServletResponse) response).sendRedirect(String.format("%s/admin/product.jsp?added=1", ((HttpServletRequest) request).getContextPath())); //NOI18N } } else if (request.getParameter("edit") != null) { //NOI18N // TODO @@ -775,7 +777,7 @@ public class PizzaServiceApplication extends BasePizzaServiceSystem implements P } @Override - public void doAdminHandleCategoryForms (final HttpServletRequest request, final HttpServletResponse response) throws ServletException { + public void doAdminHandleCategoryForms (final ServletRequest request, final ServletResponse response) throws ServletException { // Trace message this.getLogger().trace(MessageFormat.format("request={0},response={1} - CALLED!", request, response)); //NOI18N @@ -791,7 +793,7 @@ public class PizzaServiceApplication extends BasePizzaServiceSystem implements P // Try this operations try { // Is it post? - if ("POST".equals(request.getMethod())) { //NOI18N + if ("POST".equals(((HttpServletRequest) request).getMethod())) { //NOI18N // Is "add/edit/delete" set? if (request.getParameter("add") != null) { //NOI18N // Is the category title already used? @@ -800,13 +802,13 @@ public class PizzaServiceApplication extends BasePizzaServiceSystem implements P this.getLogger().debug("Already used, redirecting ..."); //NOI18N // Already added, so redirect here, else a ServletException will be thrown - response.sendRedirect(String.format("%s/admin/category.jsp?already=1", request.getContextPath())); //NOI18N + ((HttpServletResponse) response).sendRedirect(String.format("%s/admin/category.jsp?already=1", ((HttpServletRequest) request).getContextPath())); //NOI18N } else { // Add new category this.doAdminAddCategory(request); // Redirect to proper URL - response.sendRedirect(String.format("%s/admin/category.jsp?added=1", request.getContextPath())); //NOI18N + ((HttpServletResponse) response).sendRedirect(String.format("%s/admin/category.jsp?added=1", ((HttpServletRequest) request).getContextPath())); //NOI18N } } else if (request.getParameter("edit") != null) { //NOI18N // TODO @@ -839,7 +841,7 @@ public class PizzaServiceApplication extends BasePizzaServiceSystem implements P * @throws java.lang.IllegalAccessException If the method cannot be accessed * @throws java.lang.reflect.InvocationTargetException Any other problems? */ - private boolean isCategoryTitleUsed (final HttpServletRequest request) throws IOException, SQLException, BadTokenException, CorruptedDatabaseFileException, NoSuchMethodException, IllegalAccessException, IllegalArgumentException, InvocationTargetException { + private boolean isCategoryTitleUsed (final ServletRequest request) throws IOException, SQLException, BadTokenException, CorruptedDatabaseFileException, NoSuchMethodException, IllegalAccessException, IllegalArgumentException, InvocationTargetException { // Trace message this.getLogger().trace(MessageFormat.format("request={0} - CALLED!", request)); //NOI18N diff --git a/src/java/org/mxchange/pizzaapplication/beans/controller/PizzaBean.java b/src/java/org/mxchange/pizzaapplication/beans/controller/PizzaBean.java index c896ff3e..1a7eda3f 100644 --- a/src/java/org/mxchange/pizzaapplication/beans/controller/PizzaBean.java +++ b/src/java/org/mxchange/pizzaapplication/beans/controller/PizzaBean.java @@ -18,14 +18,10 @@ package org.mxchange.pizzaapplication.beans.controller; import java.util.Iterator; import javax.faces.FacesException; -import javax.servlet.ServletContext; import javax.servlet.ServletException; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; +import javax.servlet.ServletRequest; import javax.servlet.http.HttpSession; -import org.apache.logging.log4j.Logger; import org.mxchange.jshop.beans.FrameworkBean; -import org.mxchange.jshop.beans.basket.BasketBean; import org.mxchange.jshop.category.Category; import org.mxchange.jshop.exceptions.CategoryTitleAlreadyUsedException; import org.mxchange.jshop.exceptions.ProductTitleAlreadyUsedException; @@ -52,7 +48,7 @@ public interface PizzaBean extends FrameworkBean { * @param session Session instance * @return Whether the product is choosen */ - public String getCheckedHtmlFromProduct (final Product product, final HttpServletRequest request, final HttpSession session); + public String getCheckedHtmlFromProduct (final Product product, final ServletRequest request, final HttpSession session); /** * Some "getter" for HTML code 'disabled="disabled"' for e.g. submit buttons @@ -62,7 +58,7 @@ public interface PizzaBean extends FrameworkBean { * @return Whether the product is choosen * @throws javax.servlet.ServletException If something unexpected happened */ - public String getDisabledHtmlFromSession (final HttpServletRequest request, final HttpSession session) throws ServletException; + public String getDisabledHtmlFromSession (final ServletRequest request, final HttpSession session) throws ServletException; /** * Somewhat setter in session @@ -122,7 +118,7 @@ public interface PizzaBean extends FrameworkBean { * @throws javax.servlet.ServletException If something unexpected happened * @throws org.mxchange.jshop.exceptions.CategoryTitleAlreadyUsedException If the given title is already used */ - public void doAdminAddCategory (final HttpServletRequest request) throws ServletException, CategoryTitleAlreadyUsedException; + public void doAdminAddCategory (final ServletRequest request) throws ServletException, CategoryTitleAlreadyUsedException; /** * Adds given product data from request to database @@ -131,7 +127,7 @@ public interface PizzaBean extends FrameworkBean { * @throws javax.servlet.ServletException If something unexpected happened * @throws org.mxchange.jshop.exceptions.ProductTitleAlreadyUsedException If the given product title is already used */ - public void doAdminAddProduct (final HttpServletRequest request) throws ServletException, ProductTitleAlreadyUsedException; + public void doAdminAddProduct (final ServletRequest request) throws ServletException, ProductTitleAlreadyUsedException; /** * Generates link HTML code for given category's parent id, if set. This @@ -145,47 +141,16 @@ public interface PizzaBean extends FrameworkBean { /** * Handles admin product form requests * - * @param request Request instance - * @param response Response instance * @throws ServletException If something unexpected happened */ - public void doAdminHandleProductForms (final HttpServletRequest request, final HttpServletResponse response) throws ServletException; + public void doAdminHandleProductForms () throws ServletException; /** * Handles admin category form requests * - * @param request Request instance - * @param response Response instance * @throws ServletException If something unexpected happened */ - public void doAdminHandleCategoryForms (final HttpServletRequest request, final HttpServletResponse response) throws ServletException; - - /** - * Getter for logger - * - * @return Logger - */ - public Logger getLogger (); - - /** - * @return the basket - */ - public BasketBean getBasket (); - - /** - * @param basket the basket to set - */ - public void setBasket (final BasketBean basket); - - /** - * @return the application - */ - public ServletContext getApplication (); - - /** - * @param application the application to set - */ - public void setApplication (final ServletContext application); + public void doAdminHandleCategoryForms () throws ServletException; /** * Some "getter" for a product from given item diff --git a/src/java/org/mxchange/pizzaapplication/beans/controller/PizzaServiceBean.java b/src/java/org/mxchange/pizzaapplication/beans/controller/PizzaServiceBean.java index e29720fb..86b10097 100644 --- a/src/java/org/mxchange/pizzaapplication/beans/controller/PizzaServiceBean.java +++ b/src/java/org/mxchange/pizzaapplication/beans/controller/PizzaServiceBean.java @@ -25,8 +25,7 @@ import javax.enterprise.context.SessionScoped; import javax.faces.FacesException; import javax.inject.Named; import javax.servlet.ServletException; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; +import javax.servlet.ServletRequest; import javax.servlet.http.HttpSession; import org.mxchange.jcore.exceptions.BadTokenException; import org.mxchange.jcore.exceptions.UnsupportedDatabaseBackendException; @@ -77,7 +76,7 @@ public class PizzaServiceBean extends BaseFrameworkBean implements PizzaBean { @PostConstruct public void init () throws FacesException { // Trace message - this.getLogger().trace(MessageFormat.format("application={0},basket={1} - CALLED!", this.getApplication(), this.getBasket())); //NOI18N + this.getLogger().trace(MessageFormat.format("application={0} - CALLED!", this.getApplication())); //NOI18N // Must not be null if (this.getApplication() == null) { @@ -103,7 +102,7 @@ public class PizzaServiceBean extends BaseFrameworkBean implements PizzaBean { * @return Whether the product is choosen */ @Override - public String getCheckedHtmlFromProduct (final Product product, final HttpServletRequest request, final HttpSession session) { + public String getCheckedHtmlFromProduct (final Product product, final ServletRequest request, final HttpSession session) { return this.app.getCheckedHtmlFromProduct(product, request, session); } @@ -115,7 +114,7 @@ public class PizzaServiceBean extends BaseFrameworkBean implements PizzaBean { * @return Whether the product is choosen */ @Override - public String getDisabledHtmlFromSession (final HttpServletRequest request, final HttpSession session) throws ServletException { + public String getDisabledHtmlFromSession (final ServletRequest request, final HttpSession session) throws ServletException { return this.app.getDisabledHtmlFromSession(request, session); } @@ -174,12 +173,12 @@ public class PizzaServiceBean extends BaseFrameworkBean implements PizzaBean { } @Override - public void doAdminAddCategory (final HttpServletRequest request) throws ServletException, CategoryTitleAlreadyUsedException { + public void doAdminAddCategory (final ServletRequest request) throws ServletException, CategoryTitleAlreadyUsedException { this.app.doAdminAddCategory(request); } @Override - public void doAdminAddProduct (final HttpServletRequest request) throws ServletException, ProductTitleAlreadyUsedException { + public void doAdminAddProduct (final ServletRequest request) throws ServletException, ProductTitleAlreadyUsedException { this.app.doAdminAddProduct(request); } @@ -194,13 +193,13 @@ public class PizzaServiceBean extends BaseFrameworkBean implements PizzaBean { } @Override - public void doAdminHandleProductForms (final HttpServletRequest request, final HttpServletResponse response) throws ServletException { - this.app.doAdminHandleProductForms(request, response); + public void doAdminHandleProductForms () throws ServletException { + this.app.doAdminHandleProductForms(this.getRequest(), this.getResponse()); } @Override - public void doAdminHandleCategoryForms (final HttpServletRequest request, final HttpServletResponse response) throws ServletException { - this.app.doAdminHandleCategoryForms(request, response); + public void doAdminHandleCategoryForms () throws ServletException { + this.app.doAdminHandleCategoryForms(this.getRequest(), this.getResponse()); } @Override diff --git a/web/admin/category.jsp b/web/admin/category.jsp index ac9678f7..296caab5 100644 --- a/web/admin/category.jsp +++ b/web/admin/category.jsp @@ -13,7 +13,7 @@ - + <% // TODO: Can be removed later diff --git a/web/admin/product.jsp b/web/admin/product.jsp index 53ba353b..d96787b5 100644 --- a/web/admin/product.jsp +++ b/web/admin/product.jsp @@ -12,6 +12,7 @@ + <% // TODO: Can be removed later diff --git a/web/form_handler/admin/do_category.jsp b/web/form_handler/admin/do_category.jsp index 27b3cd7d..7587ba18 100644 --- a/web/form_handler/admin/do_category.jsp +++ b/web/form_handler/admin/do_category.jsp @@ -9,12 +9,15 @@ <%@page import="org.mxchange.pizzaapplication.beans.controller.PizzaBean"%> + + + <%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> <% // Handle forms - controller.doAdminHandleCategoryForms(request, response); + controller.doAdminHandleCategoryForms(); %> diff --git a/web/form_handler/admin/do_product.jsp b/web/form_handler/admin/do_product.jsp index 87cd6dc9..c076d47f 100644 --- a/web/form_handler/admin/do_product.jsp +++ b/web/form_handler/admin/do_product.jsp @@ -9,12 +9,15 @@ <%@page import="org.mxchange.pizzaapplication.beans.controller.PizzaBean"%> + + + <%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> <% // Handle forms - controller.doAdminHandleProductForms(request, response); + controller.doAdminHandleProductForms(); %>