コード例 #1
0
  @RequestMapping(value = "search.htm")
  public ModelAndView search(
      HttpServletRequest httpRequest, @ModelAttribute HolidayCriteria holiday) {
    if (logger.isInfoEnabled()) {
      logger.info(this.getClass().toString() + "-Search-");
    }
    ModelAndView mav = new ModelAndView();

    mav.addObject(BuckWaConstants.PAGE_SELECT, BuckWaConstants.LEAVE_INIT);

    mav.setViewName("holidayList");

    try {
      PagingBean bean = new PagingBean();
      int offset = ServletRequestUtils.getIntParameter(httpRequest, "pager.offset", 0);
      bean.setOffset(offset);
      BuckWaRequest request = new BuckWaRequest();
      request.put("pagingBean", bean);
      bean.put("holiday", holiday);

      BuckWaResponse response = yearService.getAll();
      List<Year> years = null;

      if (response.getStatus() == BuckWaConstants.SUCCESS) {
        years = (List) response.getResObj("yearList");

        response = holidayService.getByOffset(request);
        if (response.getStatus() == BuckWaConstants.SUCCESS) {
          PagingBean beanReturn = (PagingBean) response.getResObj("pagingBean");
          bean.setCurrentPageItem(beanReturn.getCurrentPageItem());
          bean.setTotalItems(beanReturn.getTotalItems());
          mav.addObject("pagingBean", bean);
          mav.addObject("doSearch", "true");
          if (years != null) {
            Calendar calendar = Calendar.getInstance();
            for (Year year : years) {
              calendar.set(Calendar.YEAR, Integer.parseInt(year.getName()));
              year.setName(
                  BuckWaDateUtils.getCustomFormat_thai_from_date(calendar.getTime(), "yyyy"));
            }
            mav.addObject("yearList", years);
          }
          mav.addObject("holidayCriteria", holiday);
        }
      } else {
        mav.addObject("errorCode", response.getErrorCode());
      }
    } catch (Exception ex) {
      ex.printStackTrace();
      mav.addObject("errorCode", "E001");
    }
    return mav;
  }
コード例 #2
0
  @RequestMapping(value = "create.htm", method = RequestMethod.POST)
  public ModelAndView createHoliday(
      HttpServletRequest httpRequest,
      @ModelAttribute HolidayCriteria holidayCriteria,
      BindingResult result) {
    if (logger.isInfoEnabled()) {
      logger.info(this.getClass().toString() + "-- create --");
    }
    ModelAndView mav = new ModelAndView();
    try {
      //			new HolidayValidator().validate(holiday, result);
      if (result.hasErrors()) {
        mav.setViewName("holidayCreate");
      } else {
        BuckWaRequest request = new BuckWaRequest();
        request.put("holidayCriteria", holidayCriteria);

        BuckWaResponse response = yearService.getAll();
        List<Year> years = null;

        years = (List) response.getResObj("yearList");
        mav.addObject("holidayCriteria", holidayCriteria);
        if (years != null) {
          Calendar calendar = Calendar.getInstance();
          for (Year year : years) {
            calendar.set(Calendar.YEAR, Integer.parseInt(year.getName()));
            year.setName(
                BuckWaDateUtils.getCustomFormat_thai_from_date(calendar.getTime(), "yyyy"));
          }
          mav.addObject("yearList", years);
        }

        response = holidayService.create(request);
        if (response.getStatus() == BuckWaConstants.SUCCESS) {
          logger.info("  Success");
          mav.addObject("holidayCriteria", new HolidayCriteria());
          mav.addObject("successCode", response.getSuccessCode());
          gotoList(mav);
        } else {
          mav.addObject("errorCode", response.getErrorCode());
          mav.setViewName("holidayCreate");
        }
      }

    } catch (Exception ex) {
      ex.printStackTrace();
      mav.addObject("errorCode", "E001");
    }
    return mav;
  }
コード例 #3
0
  private ModelAndView gotoList(ModelAndView mav) {
    if (logger.isInfoEnabled()) {
      logger.info(this.getClass().toString() + "-goToList-");
    }
    mav.addObject(BuckWaConstants.PAGE_SELECT, BuckWaConstants.LEAVE_INIT);

    PagingBean bean = new PagingBean();

    mav.addObject("holidayCriteria", new HolidayCriteria());
    mav.addObject("pagingBean", bean);
    mav.setViewName("holidayList");

    int offset = 0;
    bean.setOffset(offset);
    BuckWaRequest request = new BuckWaRequest();
    request.put("pagingBean", bean);

    bean.put("holiday", new HolidayCriteria());

    BuckWaResponse response = yearService.getAll();
    List<Year> years = null;

    if (response.getStatus() == BuckWaConstants.SUCCESS) {
      years = (List) response.getResObj("yearList");

      response = holidayService.getByOffset(request);

      if (response.getStatus() == BuckWaConstants.SUCCESS) {
        PagingBean beanReturn = (PagingBean) response.getResObj("pagingBean");
        bean.setCurrentPageItem(beanReturn.getCurrentPageItem());
        bean.setTotalItems(beanReturn.getTotalItems());
        mav.addObject("pagingBean", bean);
        if (years != null) {
          Calendar calendar = Calendar.getInstance();
          for (Year year : years) {
            calendar.set(Calendar.YEAR, Integer.parseInt(year.getName()));
            year.setName(
                BuckWaDateUtils.getCustomFormat_thai_from_date(calendar.getTime(), "yyyy"));
          }
          mav.addObject("yearList", years);
        }
      }
    } else {
      mav.addObject("errorCode", response.getErrorCode());
    }
    return mav;
  }