diff --git a/pom.xml b/pom.xml index 79f2417..cf8e714 100644 --- a/pom.xml +++ b/pom.xml @@ -174,6 +174,13 @@ 5.4.0 test + + + + javaee + javaee-api + 5 + diff --git a/src/main/java/de/hsel/itech/jsf/CartBean.java b/src/main/java/de/hsel/itech/jsf/CartBean.java index 32a52b0..6a38aa0 100644 --- a/src/main/java/de/hsel/itech/jsf/CartBean.java +++ b/src/main/java/de/hsel/itech/jsf/CartBean.java @@ -1,6 +1,7 @@ package de.hsel.itech.jsf; import de.hsel.itech.db.Database; +import de.hsel.itech.db.pojo.Book; import de.hsel.itech.db.pojo.ShoppingCartItem; import de.hsel.itech.db.pojo.User; import lombok.Getter; @@ -9,6 +10,7 @@ import lombok.Setter; import javax.faces.annotation.ManagedProperty; import javax.faces.bean.ManagedBean; import javax.faces.bean.RequestScoped; +import javax.faces.context.FacesContext; import java.util.ArrayList; import java.util.List; @@ -16,11 +18,30 @@ import java.util.List; @RequestScoped public class CartBean { - @Getter @Setter @ManagedProperty("#{userBean.user}") private User user; + @Setter + @Getter + private long isbn; + + public User getUser() { + FacesContext context = FacesContext.getCurrentInstance(); + return (User) context.getApplication().evaluateExpressionGet(context,"#{userBean.user}", User.class); + } + + public String add(){ + System.out.println("isbn: " + isbn); + if(Database.getInstance().book().exists(isbn)){ + Book book = Database.getInstance().book().get(isbn); + Database.getInstance().shoppingCart().insert(new ShoppingCartItem(user,book,1)); + }else{ + return "index.jsf"; + } + return "cart.jsf"; + } + public List getItems(){ Database db = Database.getInstance(); if(user==null){ diff --git a/src/main/webapp/bookinfo.xhtml b/src/main/webapp/bookinfo.xhtml index c05ee7b..971be90 100644 --- a/src/main/webapp/bookinfo.xhtml +++ b/src/main/webapp/bookinfo.xhtml @@ -13,6 +13,12 @@ +
+ + + + in den Warenkorb +
@@ -49,10 +55,14 @@

- - - in den Warenkorb - + + + + + in den Warenkorb + +
diff --git a/src/main/webapp/cart.xhtml b/src/main/webapp/cart.xhtml index 90d4bc6..a8bc1ef 100644 --- a/src/main/webapp/cart.xhtml +++ b/src/main/webapp/cart.xhtml @@ -9,20 +9,20 @@ + #{cartBean.isbn} +
  • - #{userBean.user.name} - #{cartBean.user.name} - +