📄 informationlistaction.java
字号:
package com.longtime.wap.module.business.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.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.module.business.common.BusinessConstant;
import com.longtime.wap.module.business.service.InformationService;
import com.longtime.wap.module.business.web.form.InformationEditForm;
/**
* 处理信息列表页请求
*
* @author gengb
* @date Nov 19, 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 {
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));
}
String informationState = informationForm.getState();
if (null == informationState) {
informationState = "";
}
/*
* pubType: 0 pub
* 1 unPub
* 2 all
* 3 overdue
*/
int pubType;
if (informationState.equalsIgnoreCase("pub")) {
pubType = 0;
} else if(informationState.equalsIgnoreCase("unPub")) {
pubType = 1;
} else if(informationState.equalsIgnoreCase("overdue")) {
pubType = 3;
} else {
pubType = 2;
}
List informationList = informationService
.getInfosByCondition(informationForm.getSearchValue(),
informationForm.getSearchType(),
informationForm.getFromDate(),
informationForm.getToDate(),
pubType,
page);
request.setAttribute(BusinessConstant.INFORMATIONS,
informationList);
request.setAttribute(PageConstant.ATTR_PAGE, page);
} 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("信息删除成功!");
if (request.getAttribute(WapConstant.WAP_GLOBAL_MESSAGES)
!= null) {
request.removeAttribute(WapConstant.WAP_GLOBAL_MESSAGES);
}
request.setAttribute(WapConstant.WAP_GLOBAL_MESSAGES, messages);
} catch (Exception ex) {
LOGGER.error(ex);
ex.printStackTrace();
}
return mapping.findForward("informations");
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -