Examples of ActionMessages


Examples of org.apache.struts.action.ActionMessages

    HttpSession session = request.getSession();
    UserObject userObject = (UserObject)session.getAttribute("userobject");

    int individualID = userObject.getIndividualID(); // logged in user

    ActionMessages allErrors = new ActionMessages();
    String forward = "displayComposeForm";

    ActionMessages messages = new ActionMessages();

    // "composeMailForm", defined in struts-config-email.xml
    DynaActionForm emailForm = (DynaActionForm)form;

    // Populate the Attachments In-Case. If we face any problem while sending
    // email.
    // Populating the ArrayList with the DDNameValue.
    ArrayList attachments = new ArrayList();
    ArrayList attachmentFileIDs = new ArrayList();
    String[] tempAttachmentMap = (String[])emailForm.get("attachments");

    if (tempAttachmentMap != null && tempAttachmentMap.length > 0) {
      for (int i = 0; i < tempAttachmentMap.length; i++) {
        String fileKeyName = tempAttachmentMap[i];
        if (fileKeyName != null) {
          int indexOfHash = fileKeyName.indexOf("#");
          if (indexOfHash != -1) {
            int lenString = fileKeyName.length();
            String fileID = fileKeyName.substring(0, indexOfHash);
            String fileName = fileKeyName.substring(indexOfHash + 1, lenString);
            attachments.add(new DDNameValue(fileID + "#" + fileName, fileName));
            attachmentFileIDs.add(new Integer(fileID));
          }
        }
      }
    }
    // Setting the Attachments to form.
    emailForm.set("attachmentList", attachments);

    try {
      MailHome home = (MailHome)CVUtility.getHomeObject("com.centraview.mail.MailHome", "Mail");
      Mail remote = home.create();
      remote.setDataSource(dataSource);

      // create a MailMessageVO
      MailMessageVO messageVO = new MailMessageVO();

      Integer messageID = new Integer(0);

      messageVO.setMessageID(messageID.intValue());

      Integer accountID = (Integer)emailForm.get("accountID");
      messageVO.setEmailAccountID(accountID.intValue());

      // IMPORTANT: Because we use this same handler to do the save "Template"
      // functionality, note the logic below. Here, we're getting the folder ID
      // for the folder where we are going to store the message. Instead of
      // writing
      // a second handler for Save Template that did almost the same exact thing
      // as this handler, I created a SaveTemplateHandler that just sets one
      // Boolean
      // request attribute named "saveTemplate". If that attribute is set to
      // true
      // here, then we'll get the folderID of the Templates folder instead of
      // the
      // Drafts folder. That is the ONLY difference between Draft and Template.
      String folderName = MailFolderVO.DRAFTS_FOLDER_NAME;
      Boolean saveTemplate = (Boolean)request.getAttribute("saveTemplate");
      if (saveTemplate != null && saveTemplate.booleanValue() == true) {
        messageID = (Integer)emailForm.get("templateID");
        folderName = MailFolderVO.TEMPLATES_FOLDER_NAME;
      } else {
        messageID = (Integer)emailForm.get("savedDraftID");
      }
      messageVO.setMessageID(messageID.intValue());
      MailFolderVO draftsFolder = remote.getEmailFolderByName(accountID.intValue(), folderName);
      messageVO.setEmailFolderID(draftsFolder.getFolderID());

      MailAccountVO accountVO = remote.getMailAccountVO(accountID.intValue());
      if (accountVO == null) {
        accountVO = new MailAccountVO();
      }

      InternetAddress fromAddress = new InternetAddress(accountVO.getEmailAddress(), accountVO
          .getAccountName());
      messageVO.setFromAddress(fromAddress.toString());

      messageVO.setReplyTo(accountVO.getReplyToAddress());

      String subject = (String)emailForm.get("subject");
      messageVO.setSubject(subject);

      String body = (String)emailForm.get("body");
      messageVO.setBody(body);

      Boolean composeInHTML = (Boolean)emailForm.get("composeInHTML");
      if (composeInHTML.booleanValue()) {
        messageVO.setContentType(MailMessageVO.PLAIN_TEXT_TYPE);
      } else {
        messageVO.setContentType(MailMessageVO.HTML_TEXT_TYPE);
      }

      // To: is *NOT* a required field here
      ArrayList toList = this.parseAddresses((String)emailForm.get("to"));
      messageVO.setToList(toList);

      ArrayList ccList = this.parseAddresses((String)emailForm.get("cc"));
      messageVO.setCcList(ccList);

      ArrayList bccList = this.parseAddresses((String)emailForm.get("bcc"));
      messageVO.setBccList(bccList);

      Date receivedDate = new Date();
      messageVO.setReceivedDate(receivedDate);

      // Handle attachments - the attachment handler puts a ArrayList
      // This ArrayList contains the list of attached fileIDs.
      // So we'll get that ArrayList, iterate through it, creating a
      // CvFileVO object for each attachment, then add that file VO
      // to the messageVO object which will take care of the rest in
      // the EJB layer. Note that in the future, we'll want to make
      // this better by not saving the attachment list on the session.
      // So if you intend to modify this code, please consult the rest
      // of the team to see if it makes sense to make that change now.
      // Also, if you make a change here, you must make sure the
      // attachment handling code in ForwardHandler reflects your changes.
      if (attachmentFileIDs != null && attachmentFileIDs.size() > 0) {
        CvFileFacade fileRemote = new CvFileFacade();

        for (int i = 0; i < attachmentFileIDs.size(); i++) {
          int fileID = ((Integer)attachmentFileIDs.get(i)).intValue();
          // get the CvFileVO from the EJB layer
          CvFileVO fileVO = fileRemote.getFile(individualID, fileID, dataSource);
          if (fileVO != null) {
            // add this attachment to the messageVO
            messageVO.addAttachedFiles(fileVO);
          }
        } // end while (attachIter.hasNext())
      } // end if (attachmentMap != null && attachmentMap.size() > 0)

      remote.saveDraft(individualID, messageVO);
      // **ATTENTION** Note the "tricky" logic here. We're using the action
      // errors framework to send a *SUCCESS* message to the user!!!
      // We're going to add a message to the error list *only* if there
      // were no errors up to this point. In all cases, we're going to save
      // the error messages and forward back to the Compose.do handler.
      if (allErrors.isEmpty()) {
        messages.add(ActionErrors.GLOBAL_MESSAGE, new ActionMessage("error.freeForm",
            "Message saved in " + folderName + " folder."));
        saveMessages(request, messages);
      }
      saveErrors(request, allErrors);

View Full Code Here

Examples of org.apache.struts.action.ActionMessages

    HttpSession session = request.getSession();
    UserObject userObject = (UserObject)session.getAttribute("userobject");

    int individualID = userObject.getIndividualID(); // logged in user

    ActionMessages allErrors = new ActionMessages();
    String forward = "closeWindow";
    String errorForward = "errorOccurred";

    DynaActionForm emailForm = (DynaActionForm)form;

    // Populate the Attachments In-Case. If we face any problem while sending
    // email.
    // Populating the ArrayList with the DDNameValue.
    ArrayList attachments = new ArrayList();
    ArrayList attachmentFileIDs = new ArrayList();
    String[] tempAttachmentMap = (String[])emailForm.get("attachments");
    if (tempAttachmentMap != null && tempAttachmentMap.length > 0) {
      for (int i = 0; i < tempAttachmentMap.length; i++) {
        String fileKeyName = tempAttachmentMap[i];

        if (fileKeyName != null) {
          int indexOfHash = fileKeyName.indexOf("#");
          if (indexOfHash != -1) {
            int lenString = fileKeyName.length();
            String fileID = fileKeyName.substring(0, indexOfHash);
            String fileName = fileKeyName.substring(indexOfHash + 1, lenString);
            attachments.add(new DDNameValue(fileID + "#" + fileName, fileName));
            attachmentFileIDs.add(new Integer(fileID));
          }
        }
      }// end of while (attachIter.hasNext())
    }// end of if (tempAttachmentMap != null && tempAttachmentMap.size() > 0)

    // Setting the Attachments to form.
    emailForm.set("attachmentList", attachments);

    try {
      MailHome home = (MailHome)CVUtility.getHomeObject("com.centraview.mail.MailHome", "Mail");
      Mail remote = home.create();
      remote.setDataSource(dataSource);

      // create a MailMessageVO
      MailMessageVO messageVO = new MailMessageVO();

      String from = (String)emailForm.get("from");
      messageVO.setFromAddress(from);
      String replyTo = (String)emailForm.get("replyTo");
      messageVO.setReplyTo(replyTo);

      String subject = (String)emailForm.get("subject");
      if (subject == null || subject.equals("")) {
        messageVO.setSubject("[No Subject] ");
      } else {
        messageVO.setSubject(subject);
      }

      String body = (String)emailForm.get("body");
      if (body == null) {
        body = "";
      }
      messageVO.setBody(body);

      Boolean composeInHTML = (Boolean)emailForm.get("composeInHTML");
      if (composeInHTML.booleanValue()) {
        messageVO.setContentType(MailMessageVO.HTML_TEXT_TYPE);
      } else {
        messageVO.setContentType(MailMessageVO.PLAIN_TEXT_TYPE);
      }

      ArrayList toList = this.parseAddresses((String)emailForm.get("to"));
      if (toList.size() <= 0) {
        allErrors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage(
            "error.general.requiredField", "To:"));
      } else {
        messageVO.setToList(toList);
      }

      ArrayList ccList = this.parseAddresses((String)emailForm.get("cc"));
      messageVO.setCcList(ccList);

      ArrayList bccList = this.parseAddresses((String)emailForm.get("bcc"));
      messageVO.setBccList(bccList);

      // TODO: figure out what headers to set when sending mail
      messageVO.setHeaders("");

      messageVO.setReceivedDate(new java.util.Date());

      // Handle attachments - the attachment handler puts a ArrayList
      // This ArrayList contains the list of attached fileIDs.
      // So we'll get that ArrayList, iterate through it, creating a
      // CvFileVO object for each attachment, then add that file VO
      // to the messageVO object which will take care of the rest in
      // the EJB layer. Note that in the future, we'll want to make
      // this better by not saving the attachment list on the session.
      // So if you intend to modify this code, please consult the rest
      // of the team to see if it makes sense to make that change now.
      // Also, if you make a change here, you must make sure the
      // attachment handling code in ForwardHandler reflects your changes.
      if (attachmentFileIDs != null && attachmentFileIDs.size() > 0) {
        CvFileFacade fileRemote = new CvFileFacade();

        for (int i = 0; i < attachmentFileIDs.size(); i++) {
          int fileID = ((Integer)attachmentFileIDs.get(i)).intValue();
          // get the CvFileVO from the EJB layer
          CvFileVO fileVO = fileRemote.getFile(individualID, fileID, dataSource);
          if (fileVO != null) {
            // add this attachment to the messageVO
            messageVO.addAttachedFiles(fileVO);
          }
        } // end while (attachIter.hasNext())
      } // end if (attachmentMap != null && attachmentMap.size() > 0)

      if (!allErrors.isEmpty()) {
        // we encountered error above and built a list of messages,
        // so save the errors to be shown to the users, and quit
        saveErrors(request, allErrors);
        return (mapping.findForward(errorForward));
      }

      try {
        // send the message
        remote.simpleMessage(individualID, messageVO);
        session.removeAttribute("AttachfileList");
      } catch (SendFailedException sfe) {

        String errorMessage = sfe.getMessage();

        // For any specific error catch and tagged inside the <error> </error>.
        // we will parse and Display to the user.
        int startOfError = errorMessage.indexOf("<error>");
        int endOfError = errorMessage.indexOf("</error>");
        if (startOfError >= 0 && endOfError >= 0) {
          String finalParsedMessage = errorMessage.substring((startOfError + 7), endOfError);
          allErrors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("error.freeForm",
              "Error while sending mail. " + finalParsedMessage));
        }// end of if (startOfError >= 0 && endOfError >= 0)
        else {
          // For any specific error catch and tagged inside the <failed>
          // </failed>.
          // it basically containg the information like successfully send
          // message to Individual List
          // and failed to send to particular Individual.
          // pass the control to errorDisplaying Page.
          int startOfFailed = errorMessage.indexOf("<failed>");
          int endOfFailed = errorMessage.indexOf("</failed>");
          if (startOfFailed >= 0 && endOfFailed >= 0) {
            String finalParsedMessage = errorMessage.substring((startOfFailed + 8), endOfFailed);
            request.setAttribute("failedMessage", finalParsedMessage);
            errorForward = "errorPage";
          }// end of if (startOfFailed >= 0 && endOfFailed >= 0)
          else {
            allErrors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("error.freeForm",
                "Error while sending mail. Please check the recipients for invalid addresses."));
          }// end of else
        }// end of else
        saveErrors(request, allErrors);
        return (mapping.findForward(errorForward));
      }
    } catch (Exception e) {
      logger.error("[execute]: Exception", e);
      // For any other error occured while sending mail.
      allErrors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("error.unknownError",
          "error.unknownError"));
      saveErrors(request, allErrors);
      return (mapping.findForward(errorForward));
    }
    return (mapping.findForward(forward));
View Full Code Here

Examples of org.apache.struts.action.ActionMessages

    HttpSession session = request.getSession(true);
    session.setAttribute("highlightmodule", "contact");
    // Check the session for an existing error message (possibly from the delete
    // handler)
    ActionMessages allErrors = (ActionMessages)session.getAttribute("listErrorMessage");
    if (allErrors != null) {
      saveErrors(request, allErrors);
      session.removeAttribute("listErrorMessage");
    }
View Full Code Here

Examples of org.apache.struts.action.ActionMessages

    HttpSession session = request.getSession(true);
    UserObject userObject = (UserObject)session.getAttribute("userobject");
    int individualId = userObject.getIndividualID();

    //  Check the session for an existing error message (possibly from the delete handler)
    ActionMessages allErrors = (ActionMessages)session.getAttribute("listErrorMessage");
    if (allErrors != null) {
      saveErrors(request, allErrors);
      session.removeAttribute("listErrorMessage");
    }
View Full Code Here

Examples of org.apache.struts.action.ActionMessages

        CVUtility.getHostName(super.getServlet().getServletContext())).getDataSource();
    HttpSession session = request.getSession(true);

    // Check the session for an existing error message (possibly from the delete
    // handler)
    ActionMessages allErrors = (ActionMessages)session.getAttribute("listErrorMessage");
    if (allErrors != null) {
      saveErrors(request, allErrors);
      session.removeAttribute("listErrorMessage");
    }
View Full Code Here

Examples of org.apache.struts.action.ActionMessages

    HttpSession session = request.getSession(true);
    UserObject userobject = (UserObject)session.getAttribute("userobject");
    int individualId = userobject.getIndividualID();

    ActionMessages allErrors = new ActionMessages();

    DynaActionForm entityForm = (DynaActionForm)form;
    EntityVO entityVO = new EntityVOX(form, request, dataSource);

    String entityName = entityVO.getName();
    if (entityName == null || entityName.length() <= 0) {
      allErrors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("error.general.requiredField",
          "Entity Name"));
    }

    entityVO.setModifiedBy(individualId);

    ContactFacade contactFacade = null;
    try {
      contactFacade = (ContactFacade)CVUtility.setupEJB("ContactFacade",
          "com.centraview.contact.contactfacade.ContactFacadeHome", dataSource);
    } catch (Exception e) {
      throw new ServletException(e);
    }

    ActionForward forward = null;
    StringBuffer path = new StringBuffer();
    // Decide if we are updating an existing or creating a new
    if (entityVO.getContactID() < 1) {
      // set the creator
      entityVO.setCreatedBy(individualId);
      // if necessary the account manager
      if (entityVO.getAccManager() < 1) {
        entityVO.setAccManager(individualId);
      }
      String marketingListSession = (String)session.getAttribute("dbid");
      int marketingList = 1;
      try {
        marketingList = Integer.valueOf(marketingListSession).intValue();
      } catch (NumberFormatException nfe) {}

      entityVO.setList(marketingList);

      if (!allErrors.isEmpty()) {
        // if there were any validation errors, show the
        // new entity form again, with error messages...
        this.saveErrors(request, allErrors);
        return mapping.findForward(".view.contact.new_entity");
      }
View Full Code Here

Examples of org.apache.struts.action.ActionMessages

      // request for the list
      // So we will not be carrying the old error. So that we will try to
      // collect the error from the Session variable
      // Then destory it after getting the Session value
      if (session.getAttribute("listErrorMessage") != null) {
        ActionMessages allErrors = (ActionMessages)session.getAttribute("listErrorMessage");
        saveErrors(request, allErrors);
        session.removeAttribute("listErrorMessage");
      }
      GroupVO groupVO = remote.getGroup(individualId, Integer.parseInt(row));
      DynaActionForm dynaForm = (DynaActionForm)form;
View Full Code Here

Examples of org.apache.struts.action.ActionMessages

  public void preprocessRequest(HttpServletRequest request)
  {
    HttpSession session = request.getSession(false);
    if (session != null)
    {
      ActionMessages messages = (ActionMessages) session.getAttribute(Globals.ERROR_KEY);
      if (messages != null)
      {
        request.setAttribute(Globals.ERROR_KEY, messages);
        session.removeAttribute(Globals.ERROR_KEY);
      }
View Full Code Here

Examples of org.apache.struts.action.ActionMessages

  String getResultString() throws JspException
  {

    // Were any error messages specified?
    ActionMessages errors = null;
    try
    {
      errors = TagUtils.getInstance().getActionMessages(pageContext, Globals.ERROR_KEY);
    }
    catch (JspException e)
    {
      TagUtils.getInstance().saveException(pageContext, e);
      throw e;
    }

    boolean errorPrefixPresent = TagUtils.getInstance().present(pageContext, null, null, getErrorPrefix());

    boolean errorSuffixPresent = TagUtils.getInstance().present(pageContext, null, null, getErrorSuffix());

    boolean requiredPrefixPresent = TagUtils.getInstance().present(pageContext, null, null, getRequiredPrefix());
   
    boolean requiredSuffixPresent = TagUtils.getInstance().present(pageContext, null, null, getRequiredSuffix());

    // Render the error messages appropriately
    StringBuffer results = new StringBuffer();

    Iterator reports = errors.get(property);

    if (reports != null && reports.hasNext())
    {

      String message = null;
View Full Code Here

Examples of org.apache.struts.action.ActionMessages

        HttpSession ssn = request.getSession(true);
        ssn.setAttribute(Globals.ALBUM_VERIFY_KEY+aform.getId(),album.getVerifyCode());
        return forward;
      }
    }
    ActionMessages msgs = new ActionMessages();
    msgs.add("verify", new ActionMessage("error.illegal_album_verify_code"));
    super.saveMessages(request, msgs);
    forward.setRedirect(false);
    return forward;
  }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.