/*
 * Generated by MyEclipse Struts
 * Template path: templates/java/JavaClass.vtl
 */
package com.yuntong.action.ajaxaction;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.sun.java_cup.internal.internal_error;
import com.yuntong.business.vo.Y_MarketInfoVO;
import com.yuntong.service.Y_IMarketManagerService;

/** 
 * MyEclipse Struts
 * Creation date: 03-31-2007
 * 
 * XDoclet definition:
 * @struts.action validate="true"
 */
public class Y_FindMarketByAreaIDAction extends Action {
	/*
	 * Generated Methods
	 */
	private Y_IMarketManagerService service;
	public Y_IMarketManagerService getService() {
		return service;
	}
	public void setService(Y_IMarketManagerService service) {
		this.service = service;
	}
	/** 
	 * Method execute
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @return ActionForward
	 * 单击地区下拉列标，变化市场下拉列表ajax
	 * @throws IOException 
	 */
	public ActionForward execute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) throws IOException {
		response.setContentType("text/xml; charset=UTF-8");
		PrintWriter out = response.getWriter();
		//得到地区编号
		String areaValue=request.getParameter("areavalue");
		int intAreaValue=Integer.parseInt(areaValue);
		//根据地区编号得到市场信息
		List list=service.findMarketInfoByAreaID(intAreaValue);
		//封装市场信息为xml格式返回
		if(list.size()>0){
			out.print("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
			out.print("<info>");
			for (int i = 0; i < list.size(); i++) {
				out.print("<market value='"+((Y_MarketInfoVO)(list.get(i))).getMarketID()+"'>");
					out.print(((Y_MarketInfoVO)(list.get(i))).getMarketName());
				out.print("</market>");
			}
			out.print("</info>");
		}else{
			out.print("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
			out.print("<info>");
			out.print("<market value='9999'>");
			out.print("---------");
			out.print("</market>");
			out.print("</info>");
		}
		return null;
	}
}