+CartBean

This commit is contained in:
Julian Hinxlage 2019-06-04 20:13:57 +02:00
parent c8b6376284
commit 1402e0fbf5
3 changed files with 70 additions and 1 deletions

View File

@ -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<ShoppingCartItem> getItems(){
Database db = Database.getInstance();
if(user==null){
return new ArrayList<ShoppingCartItem>();
}
return db.shoppingCart().get(user);
}
public void setItems(List<ShoppingCartItem> list) {
}
public int getItemCount(){
return getItems().size();
}
}

View File

@ -0,0 +1,29 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
xmlns:f="http://xmlns.jcp.org/jsf/core">
<f:view>
<ui:composition template="template.xhtml">
<ui:define name="content">
<ui:repeat value="#{cartBean.items}" var="item">
<li>
<h:outputLabel value="#{item.article.title}"/>
</li>
</ui:repeat>
#{userBean.user.name}
#{cartBean.user.name}
<div class="m-row">
<div class="m-col-t-3 m-push-t-5 m-button m-success">
<a href="#">Jetzt Kaufen</a>
</div>
</div>
</ui:define>
</ui:composition>
</f:view>
</html>

View File

@ -38,7 +38,7 @@
<div class="m-row"> <div class="m-row">
<ol class="m-col-t-6 m-col-m-none"> <ol class="m-col-t-6 m-col-m-none">
<li><a href="category.xhtml">Katalog</a></li> <li><a href="category.xhtml">Katalog</a></li>
<li><a href="#">(1) Warenkorb</a></li> <li><a href="cart.jsf">(#{cartBean.itemCount}) Warenkorb</a></li>
</ol> </ol>
<h:panelGroup layout="block" rendered="#{userBean.loggedIn}"> <h:panelGroup layout="block" rendered="#{userBean.loggedIn}">
<ol class="m-col-t-6 m-col-m-none" start="4"> <ol class="m-col-t-6 m-col-m-none" start="4">