Package com.opensymphony.xwork2

Examples of com.opensymphony.xwork2.ValidationAware


            Object action = invocation.getAction();
            if (action instanceof ValidationAware) {
                // retrieve error / message from session
                Map session = (Map) invocation.getInvocationContext().get(ActionContext.SESSION);
                ValidationAware validationAwareAction = (ValidationAware) action;

                LOG.debug("retrieve error / message from session to populate into action ["+action+"]");

                Collection actionErrors = (Collection) session.get(actionErrorsSessionKey);
                Collection actionMessages = (Collection) session.get(actionMessagesSessionKey);
                Map fieldErrors = (Map) session.get(fieldErrorsSessionKey);

                if (actionErrors != null && actionErrors.size() > 0) {
                    Collection mergedActionErrors = mergeCollection(validationAwareAction.getActionErrors(), actionErrors);
                    validationAwareAction.setActionErrors(mergedActionErrors);
                }

                if (actionMessages != null && actionMessages.size() > 0) {
                    Collection mergedActionMessages = mergeCollection(validationAwareAction.getActionMessages(), actionMessages);
                    validationAwareAction.setActionMessages(mergedActionMessages);
                }

                if (fieldErrors != null && fieldErrors.size() > 0) {
                    Map mergedFieldErrors = mergeMap(validationAwareAction.getFieldErrors(), fieldErrors);
                    validationAwareAction.setFieldErrors(mergedFieldErrors);
                }
                session.remove(actionErrorsSessionKey);
                session.remove(actionMessagesSessionKey);
                session.remove(fieldErrorsSessionKey);
            }
View Full Code Here


                // store error / messages into session
                Map session = (Map) invocation.getInvocationContext().get(ActionContext.SESSION);

                LOG.debug("store action ["+action+"] error/messages into session ");

                ValidationAware validationAwareAction = (ValidationAware) action;
                session.put(actionErrorsSessionKey, validationAwareAction.getActionErrors());
                session.put(actionMessagesSessionKey, validationAwareAction.getActionMessages());
                session.put(fieldErrorsSessionKey, validationAwareAction.getFieldErrors());
            }
            else {
                LOG.debug("Action ["+action+"] is not ValidationAware, no message / error that are storeable");
            }
        }
View Full Code Here

        String jsonEnabled = request.getParameter(VALIDATE_JSON_PARAM);

        if (jsonEnabled != null && "true".equals(jsonEnabled)) {
            if (action instanceof ValidationAware) {
                // generate json
                ValidationAware validationAware = (ValidationAware) action;
                if (validationAware.hasErrors()) {
                    if (validationFailedStatus >= 0)
                        response.setStatus(validationFailedStatus);
                    response.setCharacterEncoding("UTF-8");
                    response.getWriter().print(buildResponse(validationAware));
                    response.setContentType("application/json");
View Full Code Here

                        LOG.debug("Session is not open, no errors / messages could be retrieve for action ["+action+"]");
                    }
                    return;
                }

                ValidationAware validationAwareAction = (ValidationAware) action;

                if (LOG.isDebugEnabled()) {
                    LOG.debug("retrieve error / message from session to populate into action ["+action+"]");
                }

                Collection actionErrors = (Collection) session.get(actionErrorsSessionKey);
                Collection actionMessages = (Collection) session.get(actionMessagesSessionKey);
                Map fieldErrors = (Map) session.get(fieldErrorsSessionKey);

                if (actionErrors != null && actionErrors.size() > 0) {
                    Collection mergedActionErrors = mergeCollection(validationAwareAction.getActionErrors(), actionErrors);
                    validationAwareAction.setActionErrors(mergedActionErrors);
                }

                if (actionMessages != null && actionMessages.size() > 0) {
                    Collection mergedActionMessages = mergeCollection(validationAwareAction.getActionMessages(), actionMessages);
                    validationAwareAction.setActionMessages(mergedActionMessages);
                }

                if (fieldErrors != null && fieldErrors.size() > 0) {
                    Map mergedFieldErrors = mergeMap(validationAwareAction.getFieldErrors(), fieldErrors);
                    validationAwareAction.setFieldErrors(mergedFieldErrors);
                }
                session.remove(actionErrorsSessionKey);
                session.remove(actionMessagesSessionKey);
                session.remove(fieldErrorsSessionKey);
            }
View Full Code Here

                if (LOG.isDebugEnabled()) {
                    LOG.debug("store action ["+action+"] error/messages into session ");
                }

                ValidationAware validationAwareAction = (ValidationAware) action;
                session.put(actionErrorsSessionKey, validationAwareAction.getActionErrors());
                session.put(actionMessagesSessionKey, validationAwareAction.getActionMessages());
                session.put(fieldErrorsSessionKey, validationAwareAction.getFieldErrors());
            }
            else if(LOG.isDebugEnabled()) {
          LOG.debug("Action ["+action+"] is not ValidationAware, no message / error that are storeable");
            }
        }
View Full Code Here

        assert cfg != null;
        return new WrapperExceptionConfig(cfg);
    }

    public void convertErrors(ActionErrors errors, Object action) {
        ValidationAware vaction = null;
        TextProvider text = null;

        if (action instanceof ValidationAware) {
            vaction = (ValidationAware)action;
        }
        if (action instanceof TextProvider) {
            text = (TextProvider)action;
        }
        // if there is no ValidationAware, it doesn't make sense to process messages
        // as there be no place to put message in
        if (vaction == null) {
            return;
        }
        for (Iterator i = errors.properties(); i.hasNext(); ) {
            String field = (String) i.next();
            for (Iterator it = errors.get(field); it.hasNext(); ) {
                ActionMessage error = (ActionMessage) it.next();
                String msg = error.getKey();
                if (error.isResource() && text != null) {
                    Object[] values = error.getValues();
                    if (values != null) {
                        msg = text.getText(error.getKey(), Arrays.asList(values));
                    } else {
                        msg = text.getText(error.getKey());
                    }
                }
                if (ActionMessages.GLOBAL_MESSAGE.equals(field)) {
                    vaction.addActionError(msg);
                } else {
                    vaction.addFieldError(field, msg);
                }
            }
        }
    }
View Full Code Here

      Object value = entry.getValue();

      if (shouldAddError(propertyName, value)) {
        Object action = invocation.getAction();
        if (action instanceof ValidationAware) {
          ValidationAware va = (ValidationAware) action;
          va.addFieldError(propertyName, getErrorMessage(
              propertyName, stack));
        }

        if (fakie == null) {
          fakie = new HashMap();
View Full Code Here

        ValueStack stack = invocationContext.getValueStack();

        Object action = invocation.getAction();
        if( action instanceof ValidationAware )
        {
            ValidationAware va = (ValidationAware) action;
            HashMap<Object, Object> propertyOverrides = new HashMap<Object, Object>();
            for( Map.Entry<String, FieldConstraintViolations> fieldViolations : fieldConstraintViolations( invocationContext )
                .entrySet() )
            {
                addConstraintViolationFieldErrors( stack, va, fieldViolations.getKey(), fieldViolations.getValue() );
View Full Code Here

      return result;
    } catch (Exception e) {
      if (this.isHandled(e)) {
        Object action = invocation.getAction();
        if (action instanceof ValidationAware) {
          ValidationAware va = (ValidationAware) action;
          Throwable cause = e.getCause();
          if (cause != null) {
            while (cause.getCause() != null) {
              cause = cause.getCause();
            }
            va.addActionError(cause.getMessage());
          } else {
            va.addActionError(e.getMessage());
          }
        }
        this.log.warn(e.getMessage(), e);
        return Struts2Constants.ERROR;
      }
View Full Code Here

          hasErrors = true;
       
        } else if (action instanceof ValidationAware && ((ValidationAware)action).hasErrors()) {
         
          // Error messages
          ValidationAware validationAwareAction = ((ValidationAware)action);
             
          Map errors = new HashMap();
          if (validationAwareAction.getActionErrors().size() > 0) {
              errors.put("actionErrors", validationAwareAction.getActionErrors());
          }
          if (validationAwareAction.getFieldErrors().size() > 0) {
              errors.put("fieldErrors", validationAwareAction.getFieldErrors());
          }
          target = errors;
          hasErrors = true;
       
        } else if (action instanceof ModelDriven) {
View Full Code Here

TOP

Related Classes of com.opensymphony.xwork2.ValidationAware

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.