removed isbn field from addbook page

set default values for year and price in addbook form
This commit is contained in:
Julian Hinxlage 2019-04-18 13:25:22 +02:00
parent 2cf2646f76
commit d3dff89b4e
3 changed files with 28 additions and 15 deletions

View File

@ -23,13 +23,13 @@ public class AddBook extends HttpServlet {
ArrayList<Book> books = db.getBooks(); ArrayList<Book> books = db.getBooks();
out.println("<form class=\"m-container\" action=\"booklist\" method=post>"); out.println("<form class=\"m-container\" action=\"booklist\" method=post>");
Utillity.addInput(out,"ISBN", "isbn");
Utillity.addInput(out,"Titel", "title"); Utillity.addInput(out,"Titel", "title");
Utillity.addInput(out,"Author", "author"); Utillity.addInput(out,"Author", "author");
Utillity.addInput(out,"Preis", "price"); Utillity.addInput(out,"Preis", "price", "0");
Utillity.addInput(out,"Jahr", "year"); Utillity.addInput(out,"Jahr", "year", "2019");
Utillity.addInput(out,"Beschreibung", "description"); Utillity.addInput(out,"Beschreibung", "description");
Utillity.addInput(out,"Verlag", "publisher"); Utillity.addInput(out,"Verlag", "publisher");
Utillity.addInput(out,"Bild", "image", "DxAzOKSiPoE");
Utillity.addTypeButton(out, "Hinzufügen", "submit"); Utillity.addTypeButton(out, "Hinzufügen", "submit");
out.println("</form>"); out.println("</form>");

View File

@ -13,6 +13,7 @@ import java.io.PrintWriter;
import java.time.Year; import java.time.Year;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Enumeration; import java.util.Enumeration;
import java.util.Random;
public class BookList extends HttpServlet { public class BookList extends HttpServlet {
@ -33,13 +34,11 @@ public class BookList extends HttpServlet {
String param = req.getParameter("removeid"); String param = req.getParameter("removeid");
if(param != null){ if(param != null){
long isbn = Long.parseLong(param); long isbn = Long.parseLong(param);
//TODO remove book from Database
db.removeBook(isbn); db.removeBook(isbn);
resp.sendRedirect("booklist");
} }
param = req.getParameter("isbn"); if(req.getParameter("title") != null){
if(param != null){
long isbn = Long.parseLong(param);
String title = req.getParameter("title"); String title = req.getParameter("title");
String author = req.getParameter("author"); String author = req.getParameter("author");
int price = Integer.parseInt(req.getParameter("price")); int price = Integer.parseInt(req.getParameter("price"));
@ -47,15 +46,15 @@ public class BookList extends HttpServlet {
String category = req.getParameter("category"); String category = req.getParameter("category");
String description = req.getParameter("description"); String description = req.getParameter("description");
String publisher = req.getParameter("publisher"); String publisher = req.getParameter("publisher");
String image = req.getParameter("image");
Book book = new Book( Book book = new Book(
0, new Random().nextInt(),
new Author(0,author), new Author(0,author),
new Publisher(0,publisher), new Publisher(0,publisher),
new Category(0,category, "DxAzOKSiPoE"), new Category(0,category, "DxAzOKSiPoE"),
title, Year.of(year),price,description, "DxAzOKSiPoE" title, Year.of(year),price,description, image
); );
//TODO add book
db.addBook(book); db.addBook(book);
resp.sendRedirect("booklist"); resp.sendRedirect("booklist");

View File

@ -18,10 +18,14 @@ public class Utillity {
} }
static public void addInput(PrintWriter out, String label, String name){ static public void addInput(PrintWriter out, String label, String name){
addInput(out,label,name,"");
}
static public void addInput(PrintWriter out, String label, String name, String value){
out.println(" <div class=\"m-row\">"); out.println(" <div class=\"m-row\">");
out.println(" <div class=\"m-col-l-2 m-push-l-5\">"); out.println(" <div class=\"m-col-l-2 m-push-l-5\">");
out.println(label); out.println(label);
out.println("<input type=\"text\" name=\"" + name + "\">"); out.println("<input type=\"text\" name=\"" + name + "\" value=\"" + value + "\">");
out.println("</div>"); out.println("</div>");
out.println("</div>"); out.println("</div>");
} }
@ -39,12 +43,22 @@ public class Utillity {
} }
static public void addTypeButton(PrintWriter out, String label, String type){ static public void addTypeButton(PrintWriter out, String label, String type){
/*
out.println(" <div class=\"m-row\">"); out.println(" <div class=\"m-row\">");
out.println(" <div class=\"m-col-l-4 m-push-l-4\">"); out.println(" <div class=\"m-col-l-4 m-push-l-4\">");
//out.println(" <div class=\"m-button m-success\">"); out.println(" <div class=\"m-button m-success\">");
out.println("<a href=\"" + "" + "\">");
out.println(label);
out.println("<input class=\"m-button m-success\" type=\"" + type + "\" value=\"" + label + "\">");
out.println("</a>");
out.println(" </div>");
out.println("</div>");
out.println("</div>");
*/
out.println(" <div class=\"m-row\">");
out.println(" <div class=\"m-col-l-4 m-push-l-5\">");
out.println(" <input type=\"" + type + "\" value=\"" + label + "\">"); out.println(" <input type=\"" + type + "\" value=\"" + label + "\">");
//out.println("<input type=" + type + " value=" + label + ">");
//out.println(" </div>");
out.println(" </div>"); out.println(" </div>");
out.println("</div>"); out.println("</div>");
} }