Пример #1
0
  /**
   * @param model
   * @param session
   * @return loginPage
   */
  @RequestMapping(value = "list", method = RequestMethod.GET)
  public String getMessageList(final Model model, final HttpSession session) {

    PageViewBean page = new PageViewBean("Messages", "All Messages");
    model.addAttribute("pageView", page);
    AppUserBean authUser = AppUtils.getAuthUserFromSession(session);

    AppUtils.trackSecretCode(authUser, MESSAGES_LIST_CODE);
    LOGGER.debug("auth user for message list: " + authUser);

    List<AppMessageBean> messages = null;

    try {
      messages = appProcessor.getMessages(authUser);
    } catch (SVAAppException e) {
      page.setValid(false);
      page.setMessage("Something's wrongs. Please try again!!");

      return "message-page";
    } catch (SVAAppBException e) {
      // page.setValid(false);
      // page.setMessage("Something's wrongs. Please try again!!");
    }

    model.addAttribute("messages", messages);

    return "message-list";
  }
Пример #2
0
  /**
   * @param model
   * @param session
   * @param messageAddBean
   * @param result
   * @return messageList
   */
  @RequestMapping(value = "add", method = RequestMethod.POST)
  public String saveMessage(
      final Model model,
      final HttpSession session,
      @ModelAttribute("messageAddBean") AppMessageBean messageAddBean,
      final BindingResult result) {

    PageViewBean page = new PageViewBean("Messages", "Add Message");
    model.addAttribute("pageView", page);

    AppUserBean authUser = AppUtils.getAuthUserFromSession(session);
    boolean isSuccess = false;

    // validate the form
    messageAddValidator.validate(messageAddBean, result);

    if (result.hasErrors()) {
      return "message-add";
    }

    try {
      isSuccess = appProcessor.saveMessage(authUser, messageAddBean);
    } catch (SVAAppException e) {
      page.setMessage("Something's wrong. Please try again!");
    } catch (SVAAppBException e) {
      page.setMessage("Save action failed!");
    }

    page.setValid(isSuccess);

    if (isSuccess) {
      page.setMessage("Message saved!!");
      return "message-page";
    }

    return "message-add";
  }