コード例 #1
0
  /** 设置 */
  @RenderMapping
  public ModelAndView setup(
      RenderRequest request, RenderResponse response, PortletPreferences prefs) {

    ModelAndView mav = new ModelAndView();

    HologramPreferenceInfo hologramPreferenceInfo = new HologramPreferenceInfo();
    if (prefs.getMap().size() != 0) {
      try {
        hologramPreferenceInfo =
            (HologramPreferenceInfo)
                preferenceInfoService.getPreferenceInfo(prefs, hologramPreferenceInfo);
      } catch (InstantiationException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      } catch (IllegalAccessException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      }
    }
    mav.addObject("tbinfo", hologramPreferenceInfo); // 将首选项保存进入ModelAndView对象中,其key为tbinfo

    mav.setViewName(
        PORTLETFOLDER + "hologram/hologramInfoPreferences"); // 返回一个视图,并保存进入ModelAndView对象中
    return mav;
  }
  /** 设置 */
  @RenderMapping
  public ModelAndView setup(
      RenderRequest request, RenderResponse response, PortletPreferences prefs) {
    ModelAndView mav = new ModelAndView();

    PreferenceInfo preferenceinfo = null;
    if (prefs.getMap().size() == 0) {
      preferenceinfo = new PreferenceInfo();
    } else {
      preferenceinfo = preferenceInfoService.getPreferenceInfo(prefs);
    }
    mav.addObject("lightsystemelectrotrend", preferenceinfo);
    mav.setViewName(PORTLETFOLDER + "energystatistic/lightSystemElectroTrendPreferences");
    return mav;
  }
  /** 设置 */
  @RenderMapping
  public ModelAndView setup(
      RenderRequest request, RenderResponse response, PortletPreferences prefs) {

    ModelAndView mav = new ModelAndView();

    PreferenceInfo preferenceinfo = null;
    if (prefs.getMap().size() == 0) {
      preferenceinfo = new PreferenceInfo();
    } else {
      preferenceinfo = preferenceInfoService.getPreferenceInfo(prefs);
    }
    mav.addObject("consumptionstatistics", preferenceinfo);

    mav.setViewName(PORTLETFOLDER + "consumptionstatistics/consumptionStatisticsPreferences");
    return mav;
  }
  /**
   * 保存
   *
   * @param buildinfo 设置对象
   * @param prefs 首选项对象
   */
  @SuppressWarnings("rawtypes")
  @ActionMapping(params = "action=savePreferences")
  public void savePreferences(
      @ModelAttribute("preferenceinfo") PreferenceInfo preferenceinfo,
      PortletPreferences prefs,
      ActionRequest request,
      ActionResponse response)
      throws PortletException, ReadOnlyException, IOException {

    List<String> errorMessages = new ArrayList<String>();
    try {
      preferenceInfoService.savePreferenceInfo(prefs, preferenceinfo);

    } catch (Exception e) {
      e.printStackTrace();
      errorMessages.add(e.getMessage());
      logger.error(e);
    }
    response.setRenderParameter("", "");
    request.setAttribute("errorMessages", errorMessages);
    request.setAttribute("successMessages", "操作成功");
  }