- Added parent_category_selection_box.jsp which holds the selection box for parent categories
- Added method generateLinkForParent()
- Fixed wrong use of COLUMN_PARENT for title
- Catched newly thrown CategoryTitleAlreadyUsedException
Signed-off-by:Roland Häder <roland@mxchange.org>
</Appenders>
<Loggers>
<Root level="trace">
+ <AppenderRef ref="STDERR" level="WARNING"/>
<AppenderRef ref="STDOUT" level="TRACE"/>
</Root>
</Loggers>
*/
package org.mxchange.pizzaapplication.application;
+import org.mxchange.pizzaapplication.exceptions.CategoryTitleAlreadyUsedException;
import java.util.Iterator;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
*
* @param request Request instance
* @throws javax.servlet.ServletException If something unexpected happened
+ * @throws org.mxchange.pizzaapplication.application.CategoryTitleAlreadyUsedException If the given title is already used
*/
- public void doAdminAddCategory (final HttpServletRequest request) throws ServletException;
+ public void doAdminAddCategory (final HttpServletRequest request) throws ServletException, CategoryTitleAlreadyUsedException;
/**
* Adds given product data from request to database
* @throws javax.servlet.ServletException If something unexpected happened
*/
public void doAdminAddProduct (final HttpServletRequest request) throws ServletException;
+
+ /**
+ * Generates link HTML code for given category's parent id, if set. This
+ * link then points to products.jsp?category_id=x
+ *
+ * @param category Category instance
+ * @return HTML code
+ */
+ public String generateLinkForParent (final Category category);
}
*/
package org.mxchange.pizzaapplication.application;
+import org.mxchange.pizzaapplication.exceptions.CategoryTitleAlreadyUsedException;
import java.io.IOException;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
* @param request Request instance
*/
@Override
- public void doAdminAddCategory (final HttpServletRequest request) throws ServletException {
+ public void doAdminAddCategory (final HttpServletRequest request) throws ServletException, CategoryTitleAlreadyUsedException {
// Trace message
this.getLogger().trace(MessageFormat.format("request={0} - CALLED!", request)); //NOI18N
// Try to check if title is used already
if (this.isCategoryUsed(request.getParameter(PizzaCategoryDatabaseConstants.COLUMN_TITLE))) {
// Title already used
- throw new IllegalArgumentException(MessageFormat.format("Title {0} is already used.", request.getParameter(PizzaCategoryDatabaseConstants.COLUMN_TITLE)));
+ throw new CategoryTitleAlreadyUsedException(request);
}
} catch (final IOException | SQLException | BadTokenException ex) {
throw new ServletException(ex);
// Trace message
this.getLogger().trace("EXIT!"); //NOI18N
}
+
+ /**
+ * Generates link HTML code for given category's parent id, if set. This
+ * link then points to products.jsp?category_id=x
+ *
+ * @param category Category instance
+ * @return HTML code
+ */
+ @Override
+ public String generateLinkForParent (final Category category) {
+ // Trace message
+ this.getLogger().trace(MessageFormat.format("category={0} - CALLED!", category));
+
+ // category must not be null
+ if (category == null) {
+ // Is null
+ throw new NullPointerException("category is null");
+ }
+
+ // Get parent id
+ Integer parent = category.getParent();
+
+ // Is the id set?
+ if (parent > 0) {
+ // Product HTML code for link
+ throw new UnsupportedOperationException(MessageFormat.format("parent={0} - Unfinished!", parent));
+ }
+
+ // No parent set
+ return "Keine";
+ }
}
while (resultSet.next()) {
// Get id, title and parent id
Integer id = resultSet.getInt(PizzaCategoryDatabaseConstants.COLUMN_ID);
- String title = resultSet.getString(PizzaCategoryDatabaseConstants.COLUMN_PARENT);
+ String title = resultSet.getString(PizzaCategoryDatabaseConstants.COLUMN_TITLE);
Integer parent = resultSet.getInt(PizzaCategoryDatabaseConstants.COLUMN_PARENT);
// Debug message
</div>
<div class="table_right">
- <select name="<%=PizzaCategoryDatabaseConstants.COLUMN_PARENT%>" size="1">
- <option value="">Ist oberste Kategorie</option>
- </select>
+ <jsp:include flush="true" page="/static/admin/parent_category_selection_box.jsp" />
</div>
<div class="clear"></div>
<%@page import="org.mxchange.pizzaapplication.application.PizzaApplication"%>
<%@page import="org.mxchange.pizzaapplication.beans.CustomerBean" %>
<%@page import="org.mxchange.pizzaapplication.product.Product"%>
+<%@page import="org.mxchange.pizzaapplication.exceptions.CategoryTitleAlreadyUsedException"%>
<%
// Init application instance
// Is "add/edit/delete" set?
if (request.getParameter("add") != null) { //NOI18N
// Add new category
- app.doAdminAddCategory(request);
+ try {
+ app.doAdminAddCategory(request);
+ } catch (final CategoryTitleAlreadyUsedException e) {
+ // Already used!
+ response.sendRedirect(request.getContextPath() + "/admin/category.jsp?already=1"); //NOI18N
+ }
} else if (request.getParameter("edit") != null) { //NOI18N
// @TODO
} else if (request.getParameter("delete") != null) { //NOI18N
--- /dev/null
+<%--
+ Document : parent_category_selection_box
+ Created on : 14.08.2015, 12:51:05
+ Author : Roland Haeder
+--%>
+
+<%@page import="org.mxchange.pizzaapplication.database.category.PizzaCategoryDatabaseConstants"%>
+
+<select name="<%=PizzaCategoryDatabaseConstants.COLUMN_PARENT%>" size="1">
+ <option value="">Ist oberste Kategorie</option>
+</select>