* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
ApplicationContext ac = WebApplicationContextUtils.getWebApplicationContext(this.getServletContext());
IGatewayService gatewayService = (IGatewayService) ac.getBean("gatewayService");
Product product = new Product();
String name = request.getParameter("name");
product.setName(name);
String areaNode = request.getParameter("areaNode");
product.setAreaNode(areaNode);
String code = request.getParameter("code");
product.setCode(code);
String weight = request.getParameter("weight");
product.setWeight(Double.parseDouble(weight));
String productImageId = request.getParameter("productImageId");
ProductImage image = null;
if(productImageId!=null) {
try {
image = gatewayService.findProductImage(new Long(productImageId));
} catch (Exception e) {
image = null;
}
}
if(image!=null) {
product.setImage(image);
}
String price = request.getParameter("price");
double pprice = 0;
try {
pprice = new Double(price);
} catch (Exception e) {
pprice = 0;
}
product.setPrice(pprice);
String leaves = request.getParameter("leaves");
int pleaves = 0;
try {
pleaves = new Integer(leaves);
} catch (Exception e) {
pleaves = 0;
}
product.setLeaves(pleaves);
String onsale = request.getParameter("onsale");
if("1".equals(onsale)) {
product.setOnsale(1);
} else {
product.setOnsale(0);
}
String areaCategoryId = request.getParameter("areaCategoryId");
AreaCategory areaCategory = null;
try {
areaCategory = gatewayService.findAreaCategory(new Long(areaCategoryId));
} catch (Exception e) {
areaCategory = null;
}
if(areaCategory!=null) {
product.setAreaCategory(areaCategory);
}
String categoryId = request.getParameter("categoryId");
Category category = null;
try {
category = gatewayService.findCategory(new Long(categoryId));
} catch (Exception e) {
category = null;
}
product.setCategory(category);
String description = request.getParameter("description");
product.setDescription(description);
gatewayService.createProduct(product);
PrintWriter out = response.getWriter();
out.print("1");