nothing is working!!!

This commit is contained in:
Julian Hinxlage 2019-06-04 21:58:44 +02:00
parent 1402e0fbf5
commit 7412c45eca
4 changed files with 46 additions and 8 deletions

View File

@ -174,6 +174,13 @@
<version>5.4.0</version> <version>5.4.0</version>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<!-- other -->
<dependency>
<groupId>javaee</groupId>
<artifactId>javaee-api</artifactId>
<version>5</version>
</dependency>
</dependencies> </dependencies>

View File

@ -1,6 +1,7 @@
package de.hsel.itech.jsf; package de.hsel.itech.jsf;
import de.hsel.itech.db.Database; 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.ShoppingCartItem;
import de.hsel.itech.db.pojo.User; import de.hsel.itech.db.pojo.User;
import lombok.Getter; import lombok.Getter;
@ -9,6 +10,7 @@ import lombok.Setter;
import javax.faces.annotation.ManagedProperty; import javax.faces.annotation.ManagedProperty;
import javax.faces.bean.ManagedBean; import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped; import javax.faces.bean.RequestScoped;
import javax.faces.context.FacesContext;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@ -16,11 +18,30 @@ import java.util.List;
@RequestScoped @RequestScoped
public class CartBean { public class CartBean {
@Getter
@Setter @Setter
@ManagedProperty("#{userBean.user}") @ManagedProperty("#{userBean.user}")
private User 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<ShoppingCartItem> getItems(){ public List<ShoppingCartItem> getItems(){
Database db = Database.getInstance(); Database db = Database.getInstance();
if(user==null){ if(user==null){

View File

@ -13,6 +13,12 @@
<h:form> <h:form>
<h:commandLink action="#{bookBean.back}" value="zurück zur Auswahl" rendered="#{not empty bookBean}"/> <h:commandLink action="#{bookBean.back}" value="zurück zur Auswahl" rendered="#{not empty bookBean}"/>
<br/>
<h:commandLink action="#{cartBean.add}">
<f:setPropertyActionListener target="#{cartBean.isbn}" value="#{bookBean.book.isbn}"/>
<i class="fas fa-cart-plus"/>
in den Warenkorb
</h:commandLink>
</h:form> </h:form>
<h:panelGroup layout="block" rendered="#{empty bookBean.book}"> <h:panelGroup layout="block" rendered="#{empty bookBean.book}">
@ -49,10 +55,14 @@
<br/> <br/>
<br/> <br/>
<div class="m-button m-success"> <div class="m-button m-success">
<a href="#"> <h:form>
<i class="fas fa-cart-plus"/> <h:commandLink action="#{cartBean.add}">
in den Warenkorb <f:setPropertyActionListener target="#{cartBean.isbn}"
</a> value="#{bookBean.book.isbn}"/>
<i class="fas fa-cart-plus"/>
in den Warenkorb
</h:commandLink>
</h:form>
</div> </div>
</div> </div>
</div> </div>

View File

@ -9,20 +9,20 @@
<ui:composition template="template.xhtml"> <ui:composition template="template.xhtml">
<ui:define name="content"> <ui:define name="content">
#{cartBean.isbn}
<ui:repeat value="#{cartBean.items}" var="item"> <ui:repeat value="#{cartBean.items}" var="item">
<li> <li>
<h:outputLabel value="#{item.article.title}"/> <h:outputLabel value="#{item.article.title}"/>
</li> </li>
</ui:repeat> </ui:repeat>
#{userBean.user.name}
#{cartBean.user.name}
<div class="m-row"> <div class="m-row">
<div class="m-col-t-3 m-push-t-5 m-button m-success"> <div class="m-col-t-3 m-push-t-5 m-button m-success">
<a href="#">Jetzt Kaufen</a> <a href="#">Jetzt Kaufen</a>
</div> </div>
</div> </div>
</ui:define> </ui:define>
</ui:composition> </ui:composition>
</f:view> </f:view>