Пример #1
0
  /**
   * Hooks into validate to catch any errors from the populate, and translate the ErrorMap to
   * ActionMessages.
   */
  @Override
  protected boolean processValidate(
      HttpServletRequest request,
      HttpServletResponse response,
      ActionForm form,
      ActionMapping mapping)
      throws IOException, ServletException, InvalidCancelException {

    // skip form validate if we had errors from populate
    if (GlobalVariables.getMessageMap().hasNoErrors()) {
      if (form == null) {
        return (true);
      }
      // Was this request cancelled?
      if (request.getAttribute(Globals.CANCEL_KEY) != null) {
        if (LOG.isDebugEnabled()) {
          LOG.debug(" Cancelled transaction, skipping validation");
        }
        return (true);
      }

      // Has validation been turned off for this mapping?
      if (!mapping.getValidate()) {
        return (true);
      }

      // call super to call forms validate
      super.processValidate(request, response, form, mapping);
    }

    publishMessages(request);
    if (!GlobalVariables.getMessageMap().hasNoErrors()) {
      // Special handling for multipart request
      if (form.getMultipartRequestHandler() != null) {
        if (LOG.isDebugEnabled()) {
          LOG.debug("  Rolling back multipart request");
        }
        form.getMultipartRequestHandler().rollback();
      }

      // Fix state that could be incorrect because of validation failure
      if (form instanceof PojoForm) {
        ((PojoForm) form).processValidationFail();
      }

      // Was an input path (or forward) specified for this mapping?
      String input = mapping.getInput();
      if (input == null) {
        if (LOG.isDebugEnabled()) {
          LOG.debug("  Validation failed but no input form available");
        }
        response.sendError(
            HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
            getInternal().getMessage("noInput", mapping.getPath()));
        return (false);
      }

      if (moduleConfig.getControllerConfig().getInputForward()) {
        ForwardConfig forward = mapping.findForward(input);
        processForwardConfig(request, response, forward);
      } else {
        internalModuleRelativeForward(input, request, response);
      }

      return (false);
    }
    return true;
  }