1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230
|
public class BidsAction extends ActionSupport implements
ScopedModelDriven<BidsModel> {
/** Session Bean Attributes */
private String scopeKey = null;
private BidsModel model = null;
private List<User> users;
private List<Product> products;
private Integer bidProduct;
private Integer bidUser;
private Float bidAmount;
// Informations tu display while typing
private String userFirstname;
// Bid to remove
private Integer bidIdToRemove;
public String initialise() {
System.out.println("BidsAction.execute");
syncAttributesFromDB();
return SUCCESS;
}
public String add() {
if (bidAmount == null) {
bidAmount = -1F;
}
System.out.println("BidsAction.post " + bidProduct + ", " + bidUser
+ ", " + bidAmount);
if (bidProduct == null || bidProduct < 1) {
System.out.println("Vous devez saisir un produit");
return INPUT;
}
if (bidUser == null || bidUser < 1) {
System.out.println("Vous devez saisir un utilisateur");
return INPUT;
}
Bid bid = new Bid();
// int productID = getProductIDFromName(bid_product);
bid.setProduct(DAOProducts.getProduct(bidProduct));
bid.setUser(DAOUser.getUser(bidUser));
bid.setBidAmount(bidAmount);
// TODO : sauvegarde n'a pas marche regarder pourquoi
DAOBids.saveBid(bid);
// Reinitialise le formulaire
bidProduct = 0;
bidUser = 0;
bidAmount = null;
syncAttributesFromDB();
return SUCCESS;
}
/**
* Supprime un Bid de la Base de Donnees
*/
public String remove() {
System.out.println("Suppression du Bid : " + bidIdToRemove);
if (bidIdToRemove == null) {
System.out.println("L'ID du bid a supprimer ne doit pas etre null");
return INPUT;
}
else if (bidIdToRemove <= 0) {
System.out.println("L'ID du bid a supprimer doit etre superieur a 0");
return INPUT;
}
// Suppression du bid
DAOBids.removeBid(bidIdToRemove);
// Reset le bid a supprimer
bidIdToRemove = null;
syncAttributesFromDB();
return SUCCESS;
}
/*
* (non-Javadoc)
*
* @see com.opensymphony.xwork2.ActionSupport#input()
*/
@Override
public String input() throws Exception {
System.out.println("METHOD BidsAction.input called");
return super.input();
}
private void syncAttributesFromDB() {
// TODO Demander a HUT comment la liste peut rester synchronisee avec la
// BD?
if (model != null) {
model.syncList();
}
users = DAOUser.getListofUsers();
products = DAOProducts.getListofProducts();
}
/**
* @return the users
*/
public List<User> getUsers() {
return users;
}
/**
* @param users
* the users to set
*/
public void setUsers(List<User> users) {
this.users = users;
}
/**
* @return the products
*/
public List<Product> getProducts() {
return products;
}
/**
* @param products
* the products to set
*/
public void setProducts(List<Product> products) {
this.products = products;
}
/**
* @return the bidProduct
*/
public Integer getBidProduct() {
return bidProduct;
}
/**
* @param bidProduct
* the bidProduct to set
*/
public void setBidProduct(Integer bidProduct) {
System.out.println("set Bid Product :" + bidProduct);
this.bidProduct = bidProduct;
}
/**
* @return the bidUser
*/
public Integer getBidUser() {
return bidUser;
}
/**
* @param bidUser
* the bidUser to set
*/
public void setBidUser(Integer bidUser) {
System.out.println("set Bid user :" + bidUser);
this.bidUser = bidUser;
}
/**
* @return the bid_bidAmount
*/
public Float getBidAmount() {
return bidAmount;
}
/**
* @param bidBidAmount
* the bid_bidAmount to set
*/
public void setBidAmount(Float bidBidAmount) {
bidAmount = bidBidAmount;
}
/**
* @return the bidIdToRemove
*/
public Integer getBidIdToRemove() {
return bidIdToRemove;
}
/**
* @param bidIdToRemove
* the bidIdToRemove to set
*/
public void setBidIdToRemove(Integer bidIdToRemove) {
this.bidIdToRemove = bidIdToRemove;
}
/**
* @return the scopeKey
*/
public String getScopeKey() {
return scopeKey;
}
/**
* @param scopeKey
* the scopeKey to set
*/
public void setScopeKey(String scopeKey) {
this.scopeKey = scopeKey;
}
/**
* @return the model
*/
public BidsModel getModel() {
return model;
}
/**
* @param model
* the model to set
*/
public void setModel(BidsModel model) {
this.model = model;
} |
Partager