~ shopping cart ammount change working without database
This commit is contained in:
parent
cc06ec797e
commit
7d443a1aeb
|
@ -8,6 +8,7 @@ import javax.faces.annotation.ManagedProperty;
|
||||||
import javax.faces.bean.ManagedBean;
|
import javax.faces.bean.ManagedBean;
|
||||||
import javax.faces.bean.SessionScoped;
|
import javax.faces.bean.SessionScoped;
|
||||||
import javax.faces.context.FacesContext;
|
import javax.faces.context.FacesContext;
|
||||||
|
import javax.faces.event.ValueChangeEvent;
|
||||||
import java.sql.Date;
|
import java.sql.Date;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -35,6 +36,9 @@ public class CartBean {
|
||||||
return (Address) context.getApplication().evaluateExpressionGet(context, "#{addressBean.selected}", Address.class);
|
return (Address) context.getApplication().evaluateExpressionGet(context, "#{addressBean.selected}", Address.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Setter
|
||||||
|
private List<ShoppingCartItem> items;
|
||||||
|
|
||||||
public String add(Book book) {
|
public String add(Book book) {
|
||||||
if (getUser() != null && getUser().getId() != 0) {
|
if (getUser() != null && getUser().getId() != 0) {
|
||||||
for (ShoppingCartItem item : getItems()) {
|
for (ShoppingCartItem item : getItems()) {
|
||||||
|
@ -58,11 +62,20 @@ public class CartBean {
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<ShoppingCartItem> getItems() {
|
public List<ShoppingCartItem> getItems() {
|
||||||
|
if(items != null) return items;
|
||||||
Database db = Database.getInstance();
|
Database db = Database.getInstance();
|
||||||
if (getUser() != null) {
|
if (getUser() != null) {
|
||||||
return db.shoppingCart().get(getUser());
|
items = db.shoppingCart().get(getUser());
|
||||||
} else {
|
} else {
|
||||||
return new ArrayList<ShoppingCartItem>();
|
items = new ArrayList<ShoppingCartItem>();
|
||||||
|
}
|
||||||
|
return items;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void change(ValueChangeEvent event) {
|
||||||
|
System.out.println("änderung");
|
||||||
|
for(ShoppingCartItem item : getItems()) {
|
||||||
|
System.out.println(item.getCount());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -38,7 +38,14 @@
|
||||||
</div>
|
</div>
|
||||||
<div class="m-row">
|
<div class="m-row">
|
||||||
<div class="m-col-t-4 m-push-t-6">
|
<div class="m-col-t-4 m-push-t-6">
|
||||||
<input type="number" name="quantity" value="#{item.count}" min="1" max="10"/>
|
<h:form>
|
||||||
|
<h:inputText value="#{item.count}" valueChangeListener="#{cartBean.change}">
|
||||||
|
<f:validateLength minimum="1" maximum="3"/>
|
||||||
|
<f:ajax />
|
||||||
|
</h:inputText>
|
||||||
|
</h:form>
|
||||||
|
|
||||||
|
<h:messages globalOnly="false"/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="m-row">
|
<div class="m-row">
|
||||||
|
|
Loading…
Reference in New Issue