Package org.apache.struts.action

Examples of org.apache.struts.action.ActionMessages


        CVUtility.getHostName(super.getServlet().getServletContext())).getDataSource();

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

    ActionMessages allErrors = new ActionMessages();

    int rowID = 0;
    int ownerId = userObject.getIndividualID();

    SaleFacadeHome mfh = (SaleFacadeHome)CVUtility.getHomeObject(
        "com.centraview.sale.salefacade.SaleFacadeHome", "SaleFacade");

    try {
      SaleFacade remote = mfh.create();
      remote.setDataSource(dataSource);

      OpportunityForm opportunityForm = (OpportunityForm)form;
      OpportunityVO opportunityVO = new OpportunityVO();

      ActivityVO activityVO = new ActivityVO();
      activityVO.setStatus(Integer.parseInt(opportunityForm.getStatusid()));
      activityVO.setTitle(opportunityForm.getTitle());
      activityVO.setActivityDetails(opportunityForm.getDescription());
      activityVO.setCreatedBy(ownerId);
      activityVO.setOwner(ownerId);

      opportunityVO.setActivityVO(activityVO);
      opportunityVO.setTitle(opportunityForm.getTitle());
      opportunityVO.setDescription(opportunityForm.getDescription());

      int entityIdInt = 0;
      String entityId = opportunityForm.getEntityid();
      try {
        entityIdInt = Integer.parseInt(entityId);
      } catch (NumberFormatException nfe) {}

      if (entityIdInt <= 0) {
        allErrors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage(
            "error.general.requiredField", "Entity"));
      }

      opportunityVO.setEntityID(entityIdInt);

      if (!opportunityForm.getIndividualid().trim().equals("")) {
        opportunityVO.setIndividualID(Integer.parseInt(opportunityForm.getIndividualid()));
      }

      opportunityVO.setOpportunityTypeID(Integer.parseInt(opportunityForm.getOpportunitytypeid()));
      opportunityVO.setStatusID(Integer.parseInt(opportunityForm.getStatusid()));
      opportunityVO.setStageID(Integer.parseInt(opportunityForm.getStageid()));

      if (!opportunityForm.getTotalamount().trim().equals("")) {
        String Totalamount = opportunityForm.getTotalamount();
        if (Totalamount != null) {
          Totalamount = Totalamount.replaceAll(" ", "");// remove empty spaces
          NumberFormat nf = NumberFormat.getInstance();
          Totalamount = nf.parse(Totalamount).toString();
        }
        opportunityVO.setActualAmount(Float.parseFloat(Totalamount));
      }

      String ForecastedAmount = opportunityForm.getForecastedamount();
      if (ForecastedAmount != null) {
        ForecastedAmount = ForecastedAmount.replaceAll(" ", "");// remove empty
                                                                // spaces
        NumberFormat nf = NumberFormat.getInstance();
        ForecastedAmount = nf.parse(ForecastedAmount).toString();
      }
      opportunityVO.setForecastedAmount(Float.parseFloat(ForecastedAmount));
      opportunityVO.setProbability(Integer.parseInt(opportunityForm.getProbabilityid()));

      if ((opportunityForm.getSourceid() != null)
          && ((opportunityForm.getSourceid()).length() > 0)) {
        opportunityVO.setSourceID(Integer.parseInt(opportunityForm.getSourceid()));
      }
      opportunityVO.setSource(opportunityForm.getSourcename());

      if (opportunityForm.getAcctmgrid() != null
          && !opportunityForm.getAcctmgrid().trim().equals("")
          && !opportunityForm.getAcctmgrid().trim().equals("0")) {
        opportunityVO.setAcctMgr(Integer.parseInt(opportunityForm.getAcctmgrid()));
      } else {
        opportunityVO.setAcctMgr(ownerId);
      }

      if (!opportunityForm.getAcctteamid().trim().equals("")) {
        opportunityVO.setAcctTeam(Integer.parseInt(opportunityForm.getAcctteamid()));
      }

      if ((opportunityForm.getEstimatedclosemonth() != null)
          && (opportunityForm.getEstimatedcloseday() != null)
          && (opportunityForm.getEstimatedcloseyear() != null)) {
        String estimatedclosemonth = opportunityForm.getEstimatedclosemonth();
        String estimatedcloseday = opportunityForm.getEstimatedcloseday();
        String estimatedcloseyear = opportunityForm.getEstimatedcloseyear();

        try {
          Timestamp eClose = DateUtility.createTimestamp(estimatedcloseyear, estimatedclosemonth,
              estimatedcloseday);
          opportunityVO.setEstimatedClose(eClose);
        } catch (Exception e) {
          logger.error("[execute]: Exception", e);
        }
      }

      if (!allErrors.isEmpty()) {
        this.saveErrors(request, allErrors);
        return mapping.findForward(".view.sales.new_opportunity");
      }

      int recordID = remote.addOpportunity(ownerId, opportunityVO);
View Full Code Here


  {
    String dataSource = Settings.getInstance().getSiteInfo(
        CVUtility.getHostName(super.getServlet().getServletContext())).getDataSource();
    ActionForward forward = null;
    try {
      ActionMessages allErrors = new ActionMessages();
      HttpSession session = request.getSession();
      int userId = ((UserObject)session.getAttribute("userobject")).getIndividualID();
      UserVO userVO = new UserVO();
      UserSettingsForm userForm = (UserSettingsForm)form;
      if (userForm.getName() != null && (userForm.getName()).length() > 0) {
        userVO.setContactID(userForm.getContactID());
      } else {
        allErrors.add("error.administration.newuser.id.required", new ActionMessage(
            "error.administration.newuser.id.required"));
      }

      String userName = userForm.getUserName();

      if (userName == null || userName.equals("")) {
        allErrors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage(
            "error.general.requiredField", "User Name"));
      }

      // letters (upper and lower), numbers, -, _, and . are valid characters in
      // usernames
      if (!userName.matches("[\\w-\\.\\@]+")) {
        allErrors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("error.freeForm",
            "User Name may only contain letters, numbers, hyphens, underscores, and periods."));
      }

      userVO.setLoginName(userName);

      if (userForm.getPassword() != null && !(userForm.getPassword()).equals("")) {
        userVO.setPassword(userForm.getPassword());
      } else {
        allErrors.add("error.administration.newuser.password.required", new ActionMessage(
            "error.administration.newuser.password.required"));
      }

      if (userForm.getUserType() != null && !(userForm.getUserType()).equals("")) {
        userVO.setUserType(userForm.getUserType());
      } else {
        allErrors.add("error.administration.newuser.usertype.required", new ActionMessage(
            "error.administration.newuser.usertype.required"));
      }

      if (userForm.getEnabled() != null && !(userForm.getEnabled()).equals("")) {
        userVO.setUserStatus(userForm.getEnabled());
      } else {
        allErrors.add("error.administration.newuser.enabled.required", new ActionMessage(
            "error.administration.newuser.enabled.required"));
      }

      if (userForm.getSecurityProfiles() != null && !(userForm.getSecurityProfiles()).isEmpty()) {
        userVO.setUserSecurityProfileId(userForm.getSecurityProfiles());
      } else {
        // Customer users do not require a security profile
        if (!userVO.getUserType().equals("CUSTOMER")) {
          allErrors.add("error.administration.newuser.securityprofiles.required",
              new ActionMessage("error.administration.newuser.securityprofiles.required"));
        }
      }

      if (!allErrors.isEmpty()) {
        // if there are any errors reported from the
        // validation done above, then save the ActionErrors
        // to the request, and forward back to the new
        // user screen so the user can fix the errors.
        saveErrors(request, allErrors);
        FORWARD_final = "userexists";
        return (mapping.findForward(FORWARD_final));
      }

      UserHome userHome = (UserHome)CVUtility.getHomeObject(
          "com.centraview.administration.user.UserHome", "User");
      User remote = userHome.create();
      remote.setDataSource(dataSource);
      remote.addUser(userId, userVO);
      String closeornew = request.getParameter("saveclosenew");
      String saveandclose = null;
      String saveandnew = null;
      if (closeornew.equals("close") || closeornew.equals("save")) {
        saveandnew = "saveandclose";
      } else if (closeornew.equals("new")) {
        saveandnew = "saveandnew";
      } else if (closeornew.equals("cancel")) {
        saveandnew = "cancel";
      }
      // set refresh and closewindow flag
      if (saveandclose != null) {
        request.setAttribute("closeWindow", "true");
      }
      request.setAttribute("refreshWindow", "true");
      request.setAttribute("actionPath", "AddUser");
      // Set Attribute as Adminitration Constant Keys for Left Navigation
      request.setAttribute("typeofmodule", AdministrationConstantKeys.USERADMINISTRATION);
      request.setAttribute("typeofsubmodule", AdministrationConstantKeys.USERADMINISTRATION_USER);
      FORWARD_final = saveandnew;
      forward = mapping.findForward(FORWARD_final);
    } catch (UserException ue) {
      logger.error("[execute] Exception thrown.", ue);
      ActionMessages errors = new ActionMessages();
      if (ue.getExceptionId() == UserException.INSERT_FAILED) {
        ActionMessage error = new ActionMessage("error.administration.newuser.db");
        errors.add("error.administration.newuser.db", error);
      } else if (ue.getExceptionId() == UserException.IO_FAILURE) {
        ActionMessage error = new ActionMessage("error.administration.newuser.io");
        errors.add("error.administration.newuser.io", error);
      }
      saveErrors(request, errors);
      FORWARD_final = "userexists";
      forward = mapping.findForward(FORWARD_final);
    } catch (Exception e) {
View Full Code Here

  protected ActionForward beforeExecute(ActionMapping mapping, ActionForm form,
      HttpServletRequest req, HttpServletResponse res) throws Exception
  {   
    if(needVerify(req)){
      FormBean fbean = (FormBean)form;
      ActionMessages msgs = validateSiteOwner(req, res, fbean);
      if(!msgs.isEmpty()){
        Iterator iter = msgs.get();
        String msg = null;
        if(iter.hasNext()){
          ActionMessage am = (ActionMessage)iter.next();
          msg = super.getMessage(req, null, am.getKey());
        }
View Full Code Here

  protected ActionForward doUpdateFriendlyName(ActionMapping mapping, ActionForm form,
      HttpServletRequest request, HttpServletResponse response)
      throws Exception {
    SiteForm sform = (SiteForm) form;
    super.validateClientId(request, sform);
    ActionMessages msgs = new ActionMessages();
   
    while (StringUtils.isNotEmpty(sform.getFriendlyName())) {
      SiteBean site = super.getSiteBean(request);
      String fn = super.autoFiltrate(site, sform.getFriendlyName());
      if(!StringUtils.equals(site.getFriendlyName(), fn)){
        //�����վ���Ƿ��Ѿ�����
        if(SiteDAO.getSiteByFriendlyName(fn) != null){
          msgs.add("friendlyName", new ActionMessage("error.site_friendlyName_exists"));
          break;
        }
        try {
          site.setFriendlyName(fn);
          SiteDAO.flush();
        } catch (Exception e) {
          msgs.add("result", new ActionMessage("error.database", e.getMessage()));
        }
      }
      break;
    }

    if (!msgs.isEmpty()) {
      saveMessages(request, msgs);
      return mapping.findForward("modify_name");
    }

    return makeForward(mapping.findForward("editsite"), sform.getSid());
View Full Code Here

  protected ActionForward doUpdateDetail(ActionMapping mapping, ActionForm form,
      HttpServletRequest request, HttpServletResponse response)
      throws Exception {
    SiteForm sform = (SiteForm) form;
    super.validateClientId(request, sform);
    ActionMessages msgs = new ActionMessages();
   
    do{
      SiteBean site = super.getSiteBean(request);
      String detail = super.autoFiltrate(site, StringUtils.extractText(sform.getDetail()));
      if(!StringUtils.equals(site.getDetail(), detail)){
        try {
          site.setDetail(detail);
          SiteDAO.flush();
        } catch (Exception e) {
          msgs.add("result", new ActionMessage("error.database", e.getMessage()));
        }
      }
      break;
    }while(true);

    if (!msgs.isEmpty()) {
      saveMessages(request, msgs);
      return mapping.findForward("modify_detail");
    }

    return makeForward(mapping.findForward("editsite"), sform.getSid());
View Full Code Here

  protected ActionForward doUpdateTitle(ActionMapping mapping, ActionForm form,
      HttpServletRequest request, HttpServletResponse response)
      throws Exception {
    SiteForm sform = (SiteForm) form;
    super.validateClientId(request, sform);
    ActionMessages msgs = new ActionMessages();
   
    do{
      SiteBean site = super.getSiteBean(request);
      String title = super.autoFiltrate(site, sform.getTitle());
      if(!StringUtils.equals(site.getTitle(), title)){
        try {
          site.setTitle(title);
          SiteDAO.flush();
        } catch (Exception e) {
          msgs.add("result", new ActionMessage("error.database", e.getMessage()));
        }
      }
      break;
    }while(true);

    if (!msgs.isEmpty()) {
      saveMessages(request, msgs);
      return mapping.findForward("modify_title");
    }

    return makeForward(mapping.findForward("editsite"), sform.getSid());
View Full Code Here

      HttpServletRequest request, HttpServletResponse response)
      throws Exception
  {
    SiteForm f_site = (SiteForm)form;
    super.validateClientId(request, f_site);
    ActionMessages msgs = new ActionMessages();
    //��֤�����
    String friendlyName = super.autoFiltrate(null, f_site.getFriendlyName());
    do{
      if(StringUtils.isEmpty(friendlyName)){
        msgs.add("friendlyName", new ActionMessage("error.site_friendlyName_empty"));
        break;
      }
      //�ж���վ���Ƿ����
      SiteBean site = super.getSiteBean(request);
      if (!StringUtils.equals(site.getFriendlyName(), friendlyName)
          && SiteDAO.getSiteByFriendlyName(friendlyName) != null) {       
        msgs.add("friendlyName", new ActionMessage("error.site_friendlyName_exists"));
        break;
      }
      if(site!=null){
        if(StringUtils.isNotEmpty(f_site.getDetail())){
          String dt = super.autoFiltrate(site, StringUtils.extractText(f_site.getDetail()));
          site.setDetail(StringUtils.abbreviate(dt,250));
        }
        else
          site.setDetail(null);
       
        if(!StringUtils.equals(site.getFriendlyName(), friendlyName))
          site.setFriendlyName(friendlyName);
       
        if(StringUtils.isNotEmpty(f_site.getIcpNumber())){
          site.setIcpNumber(DLOGSecurityManager.IllegalGlossary
              .deleteIllegalWord(f_site.getIcpNumber()));
        }
        else
          site.setIcpNumber(null);
        site.setLastTime(new Date());
        if(StringUtils.isNotEmpty(f_site.getTitle()))
          site.setTitle(super.autoFiltrate(site, f_site.getTitle()));
        else
          site.setTitle(site.getFriendlyName());
       
        if(StringUtils.isNotEmpty(f_site.getUrl()))
          if(f_site.getUrl().toLowerCase().startsWith("http://"))
            site.setUrl(f_site.getUrl().substring(7));
          else
            site.setUrl(f_site.getUrl());
        else
          site.setUrl(null);
       
        try{
          SiteDAO.updateSite(site);
          msgs.add("site", new ActionMessage("site.updated"));
        }catch(Exception e){
          context().log("Update site failed.", e);
          msgs.add("site", new ActionMessage("error.database", e.getMessage()));
        }
      }
      break;
    }while(true);
   
    if(!msgs.isEmpty())
      saveMessages(request, msgs);
   
    return mapping.getInputForward();
  }
View Full Code Here

      HttpServletRequest request, HttpServletResponse response)
      throws Exception
  {
    SiteForm f_site = (SiteForm)form;
    super.validateClientId(request, f_site);
    ActionMessages msgs = new ActionMessages();
   
    SiteBean site = super.getSiteBean(request);
    if(site!=null){
      if(StringUtils.isNotEmpty(f_site.getLayoutFile()) &&
          !StringUtils.equals(f_site.getLayoutFile(), site.getStyle().getLayout()))
        site.getStyle().setLayout(f_site.getLayoutFile());
      else
        site.getStyle().setLayout("1");
     
      if(StringUtils.isNotEmpty(f_site.getCssFile()) &&
          !StringUtils.equals(f_site.getCssFile(), site.getStyle().getCss()))
        site.getStyle().setCss(f_site.getCssFile());
      else
        site.getStyle().setCss("main.css");
     
      //TODO: ����LOGO
     
      site.setLastTime(new Date());
      try{
        SiteDAO.updateSite(site);
      }catch(Exception e){
        context().log("Update site's style failed.", e);
        msgs.add("site", new ActionMessage("error.database", e.getMessage()));
      }
    }
   
    if(!msgs.isEmpty()){
      saveMessages(request, msgs);
      return mapping.findForward("style-setting");
    }
   
    return makeForward(mapping.findForward("settings"), f_site.getSid());
View Full Code Here

      HttpServletRequest request, HttpServletResponse response)
      throws Exception
  {
    SiteForm f_site = (SiteForm)form;
    super.validateClientId(request, f_site);
    ActionMessages msgs = new ActionMessages();
   
    SiteBean site = super.getSiteBean(request);
    if(site!=null){
      //TODO: ���Ƴ���
      // Diary
      if (StringUtils.isEmpty(f_site.getDiaryName()))
        site.setDiary(null);
      else
        site.setDiary(super.autoFiltrate(site, f_site.getDiaryName()));
      site
          .getFunctionStatus()
          .setDiary(
              (f_site.getStatusDiary() == 1) ? FunctionStatus.STATUS_NORMAL
                  : FunctionStatus.STATUS_CLOSED);
      // Photo
      if (StringUtils.isEmpty(f_site.getPhotoName()))
        site.setPhoto(null);
      else
        site.setPhoto(super.autoFiltrate(site, f_site.getPhotoName()));
      site
          .getFunctionStatus()
          .setPhoto(
              (f_site.getStatusPhoto() == 1) ? FunctionStatus.STATUS_NORMAL
                  : FunctionStatus.STATUS_CLOSED);
      // Music
      if (StringUtils.isEmpty(f_site.getMusicName()))
        site.setMusic(null);
      else
        site.setMusic(super.autoFiltrate(site, f_site.getMusicName()));
      site
          .getFunctionStatus()
          .setMusic(
              (f_site.getStatusMusic() == 1) ? FunctionStatus.STATUS_NORMAL
                  : FunctionStatus.STATUS_CLOSED);
      // BBS
      if (StringUtils.isEmpty(f_site.getForumName()))
        site.setForum(null);
      else
        site.setForum(super.autoFiltrate(site, f_site.getForumName()));
      site
          .getFunctionStatus()
          .setForum(
              (f_site.getStatusForum() == 1) ? FunctionStatus.STATUS_NORMAL
                  : FunctionStatus.STATUS_CLOSED);
      // Guestbook
      if (StringUtils.isEmpty(f_site.getGuestbookName()))
        site.setGuestbook(null);
      else
        site.setGuestbook(super.autoFiltrate(site, f_site
            .getGuestbookName()));
      site
          .getFunctionStatus()
          .setGuestbook(
              (f_site.getStatusGuestbook() == 1) ? FunctionStatus.STATUS_NORMAL
                  : FunctionStatus.STATUS_CLOSED);
     
      site.setLastTime(new Date());
      try{
        SiteDAO.updateSite(site);
      }catch(Exception e){
        context().log("Update site's functions failed.", e);
        msgs.add("site", new ActionMessage("error.database", e.getMessage()));
      }
    }
   
    if(!msgs.isEmpty()){
      saveMessages(request, msgs);
      return mapping.findForward("funcs-setting");
    }
   
    return makeForward(mapping.findForward("settings"), f_site.getSid());
View Full Code Here

   * @param form
   * @return
   */
  protected static ActionMessages validateSiteOwner(HttpServletRequest req,
      HttpServletResponse res, FormBean form) {
    ActionMessages msgs = new ActionMessages();
    do{
      if (form.getSid() < 1) {
        msgs.add("site", new ActionMessage("error.site_not_available"));
        break;
      }
      SiteBean site = getSiteByID(form.getSid());
      if (site == null) {
        msgs.add("site", new ActionMessage("error.site_not_available"));
        break;
      }
      UserBean loginUser = getLoginUser(req, res);
      if (loginUser == null) {
        msgs.add("user", new ActionMessage("error.user_not_login"));
        break;
      }
      if (loginUser.getStatus() != UserBean.STATUS_NORMAL) {
        msgs.add("user", new ActionMessage("error.user_not_available"));
        break;
      }
      if (!site.isOwner(loginUser)) {
        msgs.add("user", new ActionMessage("error.access_deny"));
        break;
      }
      req.setAttribute(KEY_SITE, site);
      req.setAttribute(KEY_USER, loginUser);
      break;
View Full Code Here

TOP

Related Classes of org.apache.struts.action.ActionMessages

Copyright © 2018 www.massapicom. 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.