74 lines
1.7 KiB
Java
74 lines
1.7 KiB
Java
package de.hsel.itech.jsf;
|
|
|
|
import de.hsel.itech.db.Database;
|
|
import de.hsel.itech.db.pojo.Address;
|
|
import de.hsel.itech.db.pojo.User;
|
|
import lombok.Getter;
|
|
import lombok.Setter;
|
|
|
|
import javax.faces.bean.ManagedBean;
|
|
import javax.faces.bean.RequestScoped;
|
|
import javax.faces.context.FacesContext;
|
|
import java.io.Serializable;
|
|
import java.util.ArrayList;
|
|
import java.util.List;
|
|
|
|
/**
|
|
*
|
|
* @author Johannes Theiner
|
|
* @version 1.0
|
|
*/
|
|
@ManagedBean
|
|
@RequestScoped
|
|
public class AddressBean implements Serializable {
|
|
|
|
public User getUser() {
|
|
FacesContext context = FacesContext.getCurrentInstance();
|
|
return (User) context.getApplication().evaluateExpressionGet(context,"#{userBean.user}", User.class);
|
|
}
|
|
|
|
@Getter
|
|
@Setter
|
|
private String name;
|
|
|
|
@Getter
|
|
@Setter
|
|
private String street;
|
|
|
|
@Getter
|
|
@Setter
|
|
private String number;
|
|
|
|
@Getter
|
|
@Setter
|
|
private int zipCode = -1;
|
|
|
|
@Getter
|
|
@Setter
|
|
private String city;
|
|
|
|
@Getter
|
|
private boolean valid = true;
|
|
|
|
|
|
public List<Address> getAddressList() {
|
|
List<Address> list = Database.getInstance().address().getAll(getUser());
|
|
if(list == null) return new ArrayList<>();
|
|
return list;
|
|
}
|
|
|
|
public String add() {
|
|
if(getUser() != null && name != null && street != null && number != null && zipCode != -1 && city != null) {
|
|
Database.getInstance().address().insert(new Address(getUser(), name, street, number, zipCode, city));
|
|
name = null;
|
|
number = null;
|
|
zipCode = -1;
|
|
city = null;
|
|
valid = true;
|
|
return "address.xhtml";
|
|
}
|
|
valid = false;
|
|
return "";
|
|
}
|
|
|
|
} |