SortAction.java
上传用户:wlfwy2004
上传日期:2016-12-12
资源大小:33978k
文件大小:2k
源码类别:

Jsp/Servlet

开发平台:

Java

  1. package com.opensource.blog.web.action;
  2. import java.util.*;
  3. import javax.servlet.http.*;
  4. import org.apache.struts.action.*;
  5. import org.apache.struts.util.*;
  6. import com.opensource.blog.model.*;
  7. import com.opensource.blog.service.*;
  8. import com.opensource.blog.web.form.*;
  9. import com.opensource.blog.web.servlet.*;
  10. public class SortAction
  11.     extends BaseAction {
  12.   private SortService sortService;
  13.   public ActionForward execute(ActionMapping actionMapping, ActionForm actionForm,
  14.                                HttpServletRequest servletRequest,
  15.                                HttpServletResponse servletResponse) {
  16.     //ActionMessages errors = new ActionMessages();
  17.     SortForm form = (SortForm) actionForm;
  18.     UserSession us = this.getUserSession(servletRequest);
  19.     if (form.getAction().equalsIgnoreCase("show")) {
  20.       MessageResources messages = getResources(servletRequest);
  21.       Locale locale = getLocale(servletRequest);
  22.       List sortSelList = new ArrayList();
  23.       List sortlist = this.getSortService().findSortsByBlogID(us.getBlog().getId().longValue());
  24.       sortSelList.add(new LabelValueBean(messages.getMessage(locale, "blog.select"), "0"));
  25.       for (int i = 0; i < sortlist.size(); i++) {
  26.         Sort sort = (Sort) sortlist.get(i);
  27.         sortSelList.add(new LabelValueBean(sort.getSortname(), String.valueOf(sort.getId())));
  28.       }
  29.       if (form.getSortid() != 0) {
  30.         Sort sort = this.getSortService().findSortByID_BlogID(form.getSortid(),
  31.             us.getBlog().getId().longValue());
  32.         if (sort != null) {
  33.           form.setUpsortname(sort.getSortname());
  34.         }
  35.       }
  36.       servletRequest.setAttribute("sortSelList", sortSelList);
  37.       servletRequest.setAttribute("sortOptForm", form);
  38.       return actionMapping.findForward("sort");
  39.     }
  40.     return actionMapping.findForward("error");
  41.   }
  42.   public SortService getSortService() {
  43.     return sortService;
  44.   }
  45.   public void setSortService(SortService sortService) {
  46.     this.sortService = sortService;
  47.   }
  48. }