Package org.apache.struts.action

Examples of org.apache.struts.action.ActionError


  String password = ((LogonForm) form).getPassword();
  Hashtable database = (Hashtable)
    servlet.getServletContext().getAttribute(Constants.DATABASE_KEY);
  if (database == null)
            errors.add(ActionErrors.GLOBAL_ERROR,
                       new ActionError("error.database.missing"));
  else {
      user = (User) database.get(username);
      if ((user != null) && !user.getPassword().equals(password))
    user = null;
      if (user == null)
                errors.add(ActionErrors.GLOBAL_ERROR,
                           new ActionError("error.password.mismatch"));
  }

  // Report any errors we have discovered back to the original form
  if (!errors.empty()) {
      saveErrors(request, errors);
View Full Code Here


        if (servlet.getDebug() >= 1) {
            servlet.log(" Checking transactional control token");
        }
        if (!isTokenValid(request))
            errors.add(ActionErrors.GLOBAL_ERROR,
                       new ActionError("error.transaction.token"));
        resetToken(request);

  // Validate the request parameters specified by the user
        if (servlet.getDebug() >= 1)
            servlet.log(" Performing extra validations");
  String value = null;
  value = regform.getUsername();
  if (("Create".equals(action)) &&
      (database.get(value) != null))
            errors.add("username",
                       new ActionError("error.username.unique",
                                       regform.getUsername()));
  if ("Create".equals(action)) {
      value = regform.getPassword();
      if ((value == null) || (value.length() <1))
                errors.add("password",
                           new ActionError("error.password.required"));
      value = regform.getPassword2();
      if ((value == null) || (value.length() < 1))
                errors.add("password2",
                           new ActionError("error.password2.required"));
  }

  // Report any errors we have discovered back to the original form
  if (!errors.empty()) {
      saveErrors(request, errors);
View Full Code Here

                (name, PageContext.REQUEST_SCOPE);
      if (value == null) {
    ;
      } else if (value instanceof String) {
    errors.add(ActionErrors.GLOBAL_ERROR,
                           new ActionError((String) value));
      } else if (value instanceof String[]) {
                String keys[] = (String[]) value;
                for (int i = 0; i < keys.length; i++)
                    errors.add(ActionErrors.GLOBAL_ERROR,
                               new ActionError(keys[i]));
            } else if (value instanceof ErrorMessages) {
    String keys[] = ((ErrorMessages) value).getErrors();
                if (keys == null)
                    keys = new String[0];
                for (int i = 0; i < keys.length; i++)
                    errors.add(ActionErrors.GLOBAL_ERROR,
                               new ActionError(keys[i]));
            } else if (value instanceof ActionErrors) {
                errors = (ActionErrors) value;
            } else {
                JspException e = new JspException
                    (messages.getMessage("errorsTag.errors",
                                         value.getClass().getName()));
                RequestUtils.saveException(pageContext, e);
                throw e;
      }
        } catch (Exception e) {
            ;
  }
        if (errors.empty())
      return (EVAL_BODY_INCLUDE);

        // Render the error messages appropriately
  StringBuffer results = new StringBuffer();
        String message = RequestUtils.message(pageContext, bundle,
                                              locale, "errors.header");
  if (message != null) {
      results.append(message);
      results.append("\r\n");
  }
        Iterator reports = null;
        if (property == null)
            reports = errors.get();
        else
            reports = errors.get(property);
        while (reports.hasNext()) {
            ActionError report = (ActionError) reports.next();
            message = RequestUtils.message(pageContext, bundle,
                                           locale, report.getKey(),
                                           report.getValues());
      if (message != null) {
    results.append(message);
    results.append("\r\n");
      }
  }
View Full Code Here

                (name, PageContext.REQUEST_SCOPE);
      if (value == null) {
    ;
      } else if (value instanceof String) {
    errors.add(ActionErrors.GLOBAL_ERROR,
                           new ActionError((String) value));
      } else if (value instanceof String[]) {
                String keys[] = (String[]) value;
                for (int i = 0; i < keys.length; i++)
                    errors.add(ActionErrors.GLOBAL_ERROR,
                               new ActionError(keys[i]));
            } else if (value instanceof ErrorMessages) {
    String keys[] = ((ErrorMessages) value).getErrors();
                if (keys == null)
                    keys = new String[0];
                for (int i = 0; i < keys.length; i++)
                    errors.add(ActionErrors.GLOBAL_ERROR,
                               new ActionError(keys[i]));
            } else if (value instanceof ActionErrors) {
                errors = (ActionErrors) value;
            } else {
                JspException e = new JspException
                    (messages.getMessage("errorsTag.errors",
                                         value.getClass().getName()));
                RequestUtils.saveException(pageContext, e);
                throw e;
      }
        } catch (Exception e) {
            ;
  }
        if (errors.empty())
      return (EVAL_BODY_INCLUDE);

        // Render the error messages appropriately
  StringBuffer results = new StringBuffer();
        String message = RequestUtils.message(pageContext, bundle,
                                              locale, "errors.header");
  if (message != null) {
      results.append(message);
      results.append("\r\n");
  }
        Iterator reports = null;
        if (property == null)
            reports = errors.get();
        else
            reports = errors.get(property);
        while (reports.hasNext()) {
            ActionError report = (ActionError) reports.next();
            message = RequestUtils.message(pageContext, bundle,
                                           locale, report.getKey(),
                                           report.getValues());
      if (message != null) {
    results.append(message);
    results.append("\r\n");
      }
  }
View Full Code Here

                (name, PageContext.REQUEST_SCOPE);
      if (value == null) {
    ;
      } else if (value instanceof String) {
    errors.add(ActionErrors.GLOBAL_ERROR,
                           new ActionError((String) value));
      } else if (value instanceof String[]) {
                String keys[] = (String[]) value;
                for (int i = 0; i < keys.length; i++)
                    errors.add(ActionErrors.GLOBAL_ERROR,
                               new ActionError(keys[i]));
            } else if (value instanceof ErrorMessages) {
    String keys[] = ((ErrorMessages) value).getErrors();
                if (keys == null)
                    keys = new String[0];
                for (int i = 0; i < keys.length; i++)
                    errors.add(ActionErrors.GLOBAL_ERROR,
                               new ActionError(keys[i]));
            } else if (value instanceof ActionErrors) {
                errors = (ActionErrors) value;
            } else {
                JspException e = new JspException
                    (messages.getMessage("errorsTag.errors",
                                         value.getClass().getName()));
                RequestUtils.saveException(pageContext, e);
                throw e;
      }
        } catch (Exception e) {
            ;
  }
        if (errors.empty())
      return (EVAL_BODY_INCLUDE);

        // Check for presence of header and footer message keys
        boolean headerPresent =
            RequestUtils.present(pageContext, bundle, locale, "errors.header");
        boolean footerPresent =
            RequestUtils.present(pageContext, bundle, locale, "errors.footer");
       
        // Render the error messages appropriately
  StringBuffer results = new StringBuffer();
        String message = null;
        if (headerPresent)
            message = RequestUtils.message(pageContext, bundle,
                                           locale, "errors.header");
        Iterator reports = null;
        if (property == null)
            reports = errors.get();
        else
            reports = errors.get(property);
       // Render header iff this is a global tag or there is an error for this property
       boolean propertyMsgPresent = reports.hasNext();
       if ((message != null)&&(property == null) || propertyMsgPresent) {
           results.append(message);
           results.append("\r\n");
       }

        while (reports.hasNext()) {
            ActionError report = (ActionError) reports.next();
            message = RequestUtils.message(pageContext, bundle,
                                           locale, report.getKey(),
                                           report.getValues());
          if (message != null) {
            results.append(message);
            results.append("\r\n");
          }
      }
View Full Code Here

                                 HttpServletRequest request) {

        ActionErrors errors = new ActionErrors();
        if ((username == null) || (username.length() < 1))
            errors.add("username",
                       new ActionError("error.username.required"));
        if (!password.equals(password2))
            errors.add("password2",
                       new ActionError("error.password.match"));
        if ((fromAddress == null) || (fromAddress.length() < 1))
            errors.add("fromAddress",
                       new ActionError("error.fromAddress.required"));
        else {
      int atSign = fromAddress.indexOf("@");
      if ((atSign < 1) || (atSign >= (fromAddress.length() - 1)))
    errors.add("fromAddress",
                           new ActionError("error.fromAddress.format",
                                           fromAddress));
  }
  if ((fullName == null) || (fullName.length() < 1))
            errors.add("fullName",
                       new ActionError("error.fullName.required"));
  if ((replyToAddress != null) && (replyToAddress.length() > 0)) {
      int atSign = replyToAddress.indexOf("@");
      if ((atSign < 1) || (atSign >= (replyToAddress.length() - 1)))
                errors.add("replyToAddress",
                           new ActionError("error.replyToAddress.format",
                                           replyToAddress));
  }

        return errors;
View Full Code Here

        ActionErrors errors = new ActionErrors();

  if ((host == null) || (host.length() < 1))
            errors.add("host",
                       new ActionError("error.host.required"));
  if ((username == null) || (username.length() < 1))
            errors.add("username",
                       new ActionError("error.username.required"));
  if ((password == null) || (password.length() < 1))
            errors.add("password",
                       new ActionError("error.password.required"));
  if ((type == null) || (type.length() < 1))
            errors.add("type",
                       new ActionError("error.type.required"));
  else if (!"imap".equals(type) && !"pop3".equals(type))
            errors.add("type",
                       new ActionError("error.type.invalid", type));

  return (errors);

    }
View Full Code Here

    public ActionErrors validate(ActionMapping mapping,
                                 HttpServletRequest request) {

        ActionErrors errors = new ActionErrors();
        if ((username == null) || (username.length() < 1))
            errors.add("username", new ActionError("error.username.required"));
        if ((password == null) || (password.length() < 1))
            errors.add("password", new ActionError("error.password.required"));

        return errors;

    }
View Full Code Here

                (name, PageContext.REQUEST_SCOPE);
      if (value == null) {
    ;
      } else if (value instanceof String) {
    errors.add(ActionErrors.GLOBAL_ERROR,
                           new ActionError((String) value));
      } else if (value instanceof String[]) {
                String keys[] = (String[]) value;
                for (int i = 0; i < keys.length; i++)
                    errors.add(ActionErrors.GLOBAL_ERROR,
                               new ActionError(keys[i]));
            } else if (value instanceof ErrorMessages) {
    String keys[] = ((ErrorMessages) value).getErrors();
                if (keys == null)
                    keys = new String[0];
                for (int i = 0; i < keys.length; i++)
                    errors.add(ActionErrors.GLOBAL_ERROR,
                               new ActionError(keys[i]));
            } else if (value instanceof ActionErrors) {
                errors = (ActionErrors) value;
      }
        } catch (Exception e) {
            ;
  }
        if (errors.empty())
      return (EVAL_BODY_INCLUDE);

  // Render the error messages appropriately
  Locale locale = null;
  try {
      locale = (Locale) pageContext.getAttribute
    (Action.LOCALE_KEY, PageContext.SESSION_SCOPE);
  } catch (IllegalStateException e) {  // Invalidated session
      locale = null;
  }
  if (locale == null)
      locale = defaultLocale;
  MessageResources messages = (MessageResources)
    pageContext.getAttribute(Action.MESSAGES_KEY,
           PageContext.APPLICATION_SCOPE);
  String message = null;
  StringBuffer results = new StringBuffer();
  message = messages.getMessage(locale, "errors.header");
  if (message != null) {
      results.append(message);
      results.append("\r\n");
  }
        Iterator reports = errors.get();
        while (reports.hasNext()) {
            ActionError report = (ActionError) reports.next();
      message =
                messages.getMessage(locale,
                                    report.getKey(), report.getValues());
      if (message != null) {
    results.append(message);
    results.append("\r\n");
      }
  }
View Full Code Here

        if (servlet.getDebug() >= 1) {
            servlet.log(" Checking transactional control token");
        }
        if (!isTokenValid(request))
            errors.add(ActionErrors.GLOBAL_ERROR,
                       new ActionError("error.transaction.token"));
        resetToken(request);

  // Validate the request parameters specified by the user
        if (servlet.getDebug() >= 1)
            servlet.log(" Performing extra validations");
  String value = null;
  value = regform.getUsername();
  if (("Create".equals(action)) &&
      (database.get(value) != null))
            errors.add("username",
                       new ActionError("error.username.unique",
                                       regform.getUsername()));
  if ("Create".equals(action)) {
      value = regform.getPassword();
      if ((value == null) || (value.length() <1))
                errors.add("password",
                           new ActionError("error.password.required"));
      value = regform.getPassword2();
      if ((value == null) || (value.length() < 1))
                errors.add("password2",
                           new ActionError("error.password2.required"));
  }

  // Report any errors we have discovered back to the original form
  if (!errors.empty()) {
      saveErrors(request, errors);
View Full Code Here

TOP

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

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.