⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 informationlistaction.java

📁 这个是完整的wap项目的源码 开发语言 Java 系统架构 Struts + hibernate + spring 数据库 Mysql5.0 应用服务器Tomcat5.0 开发工具 MyEc
💻 JAVA
字号:
package com.longtime.wap.module.information.web.action;

import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.commons.validator.GenericValidator;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.util.LabelValueBean;
import org.springframework.web.struts.DispatchActionSupport;

import com.longtime.wap.common.WapConstant;
import com.longtime.wap.common.web.Page;
import com.longtime.wap.common.web.PageConstant;
import com.longtime.wap.frame.common.UserSessionVO;
import com.longtime.wap.model.Business;
import com.longtime.wap.module.information.common.InformationConstant;
import com.longtime.wap.module.information.service.InformationService;
import com.longtime.wap.module.information.web.form.InformationEditForm;

/**
 * 处理信息列表的请求
 * 
 * @author bulc
 * @date Nov 15, 2007
 */
public class InformationListAction extends DispatchActionSupport {
	private static final Log LOGGER = 
		LogFactory.getLog(InformationListAction.class);
	private InformationService informationService;

	/**
	 * 注入服务对象
	 * 
	 * @param informationService 
	 * 						服务对象
	 */
	public void setInformationService(InformationService informationService) {
		this.informationService = informationService;
	}

	/**
	 * 处理信息列表的请求
	 * 
	 * @param mapping 
	 * 				ActionMapping对象
	 * @param form 
	 * 				ActionForm对象
	 * @param request 
	 * 				HttpServletRequest对象
	 * @param response 
	 * 				HttpServletResponse对象
	 * @return ActionForward对象
	 * @throws Exception 
	 * 				异常对象
	 */
	@SuppressWarnings("unchecked")
	public ActionForward listInformation(ActionMapping mapping,
			ActionForm form, HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		try {
			UserSessionVO usVo = 
				(UserSessionVO)request.getSession().
				getAttribute(WapConstant.USER_SESSION);
			InformationEditForm informationForm = (InformationEditForm) form;
			Page page = null;
			String pageNumber = request.getParameter(PageConstant.PARA_PAGE);

			if (GenericValidator.isBlankOrNull(pageNumber)) {
				if (GenericValidator.isBlankOrNull(
						informationForm.getCurrentPage())){
					page = new Page(1);
				} else {
					page = 
						new Page(
								Integer.parseInt(
										informationForm.getCurrentPage()));
				}
			} else {
				page = new Page(Integer.parseInt(pageNumber));
			}
			
			long cpId = 0;
			long businessId = 0;
			if (usVo.getUserGroup() == 1) {
				cpId = usVo.getCpId();
			}
			if (null != informationForm.getBusinessId() 
					&& informationForm.getBusinessId().length() > 0) {
				businessId = Long.parseLong(informationForm.getBusinessId());
			}
			request.setAttribute(InformationConstant.INFORMATIONS, 
					informationService.getInfosByCondition(
							informationForm.getSearchValue(),
							informationForm.getSearchType(), 
							cpId, 
							businessId, 
							page));
			request.setAttribute(PageConstant.ATTR_PAGE, page);
			if (usVo.getUserGroup() == 1) {
				List businesses = this.informationService.getBusinesses(cpId);
				List returnBusinesses = new ArrayList();
				returnBusinesses.add(new LabelValueBean("----请选择----",""));
				for (int i = 0; i < businesses.size(); i ++) {
					Business business = (Business) businesses.get(i);
					returnBusinesses.add(
							new LabelValueBean(business.getBusinessName(), 
									String.valueOf(business.getBusinessId())));
				}
				request.setAttribute(InformationConstant.BUSINESSES, 
						returnBusinesses);
			}
		} catch (Exception ex) {
			LOGGER.error(ex);
			ex.printStackTrace();
		}
		return mapping.findForward("listInformation");
	}

	/**
	 * 处理批量保存信息的请求
	 * 
	 * @param mapping 
	 * 				ActionMapping对象
	 * @param form 
	 * 				ActionForm对象
	 * @param request 
	 * 				HttpServletRequest对象
	 * @param response 
	 * 				HttpServletResponse对象
	 * @return ActionForward对象
	 * @throws Exception 
	 * 				异常对象
	 */
	public ActionForward saveInformations(ActionMapping mapping,
			ActionForm form, HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		List<String> messages = new ArrayList<String>();
		try {
			String[] informationIds;
			boolean isPub;
			if ("true".equalsIgnoreCase(request.getParameter("isPub"))){
				isPub = true;
				informationIds = 
					request.getParameterValues("pubInformationIds");
			} else {
				isPub = false;
				informationIds = 
					request.getParameterValues("unPubInformationIds");
			}
			this.informationService.savePubStatus(informationIds, isPub);
			messages.add("信息状态更新成功!");
		} catch (Exception ex) {
			LOGGER.error(ex);
			ex.printStackTrace();
		}
		request.setAttribute(WapConstant.WAP_GLOBAL_MESSAGES, messages);
		return mapping.findForward("informations");
	}
	
	/**
	 * 处理批量删除信息的请求
	 * 
	 * @param mapping 
	 * 				ActionMapping对象
	 * @param form 
	 * 				ActionForm对象
	 * @param request 
	 * 				HttpServletRequest对象
	 * @param response 
	 * 				HttpServletResponse对象
	 * @return ActionForward对象
	 * @throws Exception 
	 * 				异常对象
	 */
	public ActionForward deleteInformations(ActionMapping mapping,
			ActionForm form, HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		List<String> messages = new ArrayList<String>();
		try {
			String[] informationIds = 
				request.getParameterValues("deleteInformationIds");
			this.informationService.deleteInformations(informationIds);
			messages.add("信息删除成功!");
		} catch (Exception ex) {
			LOGGER.error(ex);
			ex.printStackTrace();
		}
		if (request.getAttribute(WapConstant.WAP_GLOBAL_MESSAGES) != null) {
			request.removeAttribute(WapConstant.WAP_GLOBAL_MESSAGES);
		}
		request.setAttribute(WapConstant.WAP_GLOBAL_MESSAGES, messages);
		return mapping.findForward("informations");
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -