From 1402e0fbf5baef810b6fb505c2ff7fccaea6b4d6 Mon Sep 17 00:00:00 2001 From: Julian Hinxlage Date: Tue, 4 Jun 2019 20:13:57 +0200 Subject: [PATCH] +CartBean --- src/main/java/de/hsel/itech/jsf/CartBean.java | 40 +++++++++++++++++++ src/main/webapp/cart.xhtml | 29 ++++++++++++++ src/main/webapp/template.xhtml | 2 +- 3 files changed, 70 insertions(+), 1 deletion(-) create mode 100644 src/main/java/de/hsel/itech/jsf/CartBean.java create mode 100644 src/main/webapp/cart.xhtml diff --git a/src/main/java/de/hsel/itech/jsf/CartBean.java b/src/main/java/de/hsel/itech/jsf/CartBean.java new file mode 100644 index 0000000..32a52b0 --- /dev/null +++ b/src/main/java/de/hsel/itech/jsf/CartBean.java @@ -0,0 +1,40 @@ +package de.hsel.itech.jsf; + +import de.hsel.itech.db.Database; +import de.hsel.itech.db.pojo.ShoppingCartItem; +import de.hsel.itech.db.pojo.User; +import lombok.Getter; +import lombok.Setter; + +import javax.faces.annotation.ManagedProperty; +import javax.faces.bean.ManagedBean; +import javax.faces.bean.RequestScoped; +import java.util.ArrayList; +import java.util.List; + +@ManagedBean +@RequestScoped +public class CartBean { + + @Getter + @Setter + @ManagedProperty("#{userBean.user}") + private User user; + + public List getItems(){ + Database db = Database.getInstance(); + if(user==null){ + return new ArrayList(); + } + return db.shoppingCart().get(user); + } + + public void setItems(List list) { + + } + + public int getItemCount(){ + return getItems().size(); + } + +} diff --git a/src/main/webapp/cart.xhtml b/src/main/webapp/cart.xhtml new file mode 100644 index 0000000..90d4bc6 --- /dev/null +++ b/src/main/webapp/cart.xhtml @@ -0,0 +1,29 @@ + + + + + + + + +
  • + +
  • +
    + + #{userBean.user.name} + #{cartBean.user.name} + +
    + +
    +
    +
    +
    + diff --git a/src/main/webapp/template.xhtml b/src/main/webapp/template.xhtml index 28d705f..0d3f8f2 100644 --- a/src/main/webapp/template.xhtml +++ b/src/main/webapp/template.xhtml @@ -38,7 +38,7 @@