Source code for /src/java/com/coolshare/springapp/web/UpdateQuantity2Controller.java

// =====================================================================//
// Author: Mark Qian <markqian@hotmail.com>                             //
// WWW: http://www.coolshare.com/                                       //
// Copyright (c) 2006, Mark Qian                                        //
//                                                                      //
// You must contact Mark Qian to get a permission of use                //
// in case you want to make any use of the codes except viewing it     //
// on Mark's site.                                                      //
//======================================================================//
package com.coolshare.springapp.web;

import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;
import org.springframework.web.servlet.mvc.Controller;
import org.springframework.web.servlet.ModelAndView;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.Serializable;
import java.util.Map;
import java.util.HashMap;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.coolshare.springapp.Util;
import com.coolshare.springapp.bus.BambooManager;
import com.coolshare.springapp.db.BambooManagerDao;
import com.coolshare.springapp.db.BambooManagerDaoJdbc;
import com.metaparadigm.jsonrpc.JSONRPCBridge;

public class UpdateQuantity2Controller implements Controller, Serializable {
	/** Logger for this class and subclasses */
	protected final Log logger = LogFactory.getLog(getClass());

	private BambooManager booMan;

	public ModelAndView handleRequest(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {

		String id = request.getParameter("id");
		String dq = request.getParameter("dq");
		int intDq = Integer.parseInt(dq);

		int updateQuantity2 = updateQuantity2(Integer.parseInt(id), intDq);
		if (updateQuantity2 > -1) {
			Util.recordItems(request.getSession(), id, intDq, logger, booMan);
		}
		Map myModel = new HashMap();

		myModel.put("ajaxReturn", new Integer(updateQuantity2));

		return new ModelAndView("ajaxReturn", "model", myModel);
	}

	public void setBambooManager(BambooManager pm) {
		booMan = pm;
	}

	public BambooManager getBambooManager() {
		return booMan;
	}

	public int updateQuantity2(int id, int dq) {
		if (booMan == null) {
			// WebApplicationContext wa =
			// WebApplicationContextUtils.getWebApplicationContext(JSONRPCBridge.().getServletContext());
			// booMan = (BambooManager) wa.getBean("bambooMan");
		}
		return booMan.updateQuantity2(id, dq);
	}
}