package com.lgx8.gateway.admin.servlet;
import java.io.IOException;
import java.io.Writer;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.context.ApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;
import com.lgx8.common.util.Constants;
import com.lgx8.gateway.entities.Supplier;
import com.lgx8.gateway.service.IGatewayService;
import freemarker.template.Template;
import freemarker.template.TemplateException;
/**
* Servlet implementation class GatewayAdminSupplierDetailServlet
*/
public class GatewayAdminSupplierDetailServlet extends GatewayAdminBaseServlet {
private static final long serialVersionUID = 1L;
/**
* @see GatewayAdminBaseServlet#GatewayAdminBaseServlet()
*/
public GatewayAdminSupplierDetailServlet() {
super();
}
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
Map<Object, Object> root = new HashMap<Object, Object>();
root.putAll(super.root);
Template temp = getConfiguration().getTemplate("supplier/SupplierDetail.ftl");
ApplicationContext ac = WebApplicationContextUtils.getWebApplicationContext(this.getServletContext());
IGatewayService gatewayService = (IGatewayService) ac.getBean("gatewayService");
String id = request.getParameter("id");
long lid = -1;
try {
lid = Long.parseLong(id);
} catch (Exception e1) {
lid = -1;
}
Supplier supplier = gatewayService.findSupplier(lid);
if(supplier!=null) {
root.put("supplier", supplier);
root.put("Supplier_List_Url", Constants.SUPPLIER_LIST_URL);
}
/* 将模板和数据模型合并 */
Writer out = response.getWriter();
try {
temp.process(root, out);
} catch (TemplateException e) {
e.printStackTrace();
}
out.flush();
}
}