nothing is working!!!
This commit is contained in:
parent
1402e0fbf5
commit
7412c45eca
7
pom.xml
7
pom.xml
|
@ -174,6 +174,13 @@
|
|||
<version>5.4.0</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<!-- other -->
|
||||
<dependency>
|
||||
<groupId>javaee</groupId>
|
||||
<artifactId>javaee-api</artifactId>
|
||||
<version>5</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
|
||||
|
|
|
@ -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<ShoppingCartItem> getItems(){
|
||||
Database db = Database.getInstance();
|
||||
if(user==null){
|
||||
|
|
|
@ -13,6 +13,12 @@
|
|||
|
||||
<h:form>
|
||||
<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:panelGroup layout="block" rendered="#{empty bookBean.book}">
|
||||
|
@ -49,10 +55,14 @@
|
|||
<br/>
|
||||
<br/>
|
||||
<div class="m-button m-success">
|
||||
<a href="#">
|
||||
<h:form>
|
||||
<h:commandLink action="#{cartBean.add}">
|
||||
<f:setPropertyActionListener target="#{cartBean.isbn}"
|
||||
value="#{bookBean.book.isbn}"/>
|
||||
<i class="fas fa-cart-plus"/>
|
||||
in den Warenkorb
|
||||
</a>
|
||||
</h:commandLink>
|
||||
</h:form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
@ -9,20 +9,20 @@
|
|||
<ui:composition template="template.xhtml">
|
||||
<ui:define name="content">
|
||||
|
||||
#{cartBean.isbn}
|
||||
|
||||
<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>
|
||||
|
|
Loading…
Reference in New Issue