/** * Add error to action in cases where token is required, but is missing or invalid. Implementations may * wish to override this method, but most should be able to get away with just overriding * {@link #internationaliseErrorMessage} * * @param action the action to add the error message to * @param errorMessageKey the error message key that will be used to internationalise the message */ protected void addInvalidTokenError(Action action, String errorMessageKey) { if (action instanceof ValidationAware) ((ValidationAware)action).addActionError(internationaliseErrorMessage(action, errorMessageKey)); }
if (actionErrors != null && actionErrors.size() > 0) { for (String error : actionErrors) { validationAware.addActionError(error);
if (actionErrors != null && actionErrors.size() > 0) { for (String error : actionErrors) { validationAware.addActionError(error);
public String intercept(ActionInvocation invocation) throws Exception { Object action = invocation.getAction(); if (action instanceof ValidationAware) { ValidationAware validationAware = (ValidationAware) action; validationAware.addFieldError("field", "field error"); validationAware.addActionMessage("action message"); validationAware.addActionError("action error"); } return invocation.invoke(); }
@Override protected String handleInvalidToken(ActionInvocation invocation) throws Exception { Object action = invocation.getAction(); String errorMessage = this.getCustomMessage(invocation, "struts.messages.invalid.token", "The form has already been processed or no token was supplied, please try again."); String message = this.getCustomMessage(invocation, "struts.messages.invalid.token.message", "Stop double-submission of forms."); if (action instanceof ValidationAware) { if (null == this.getTypeMessages() || this.getTypeMessages().equalsIgnoreCase(TYPE_RETURN_NONE_MESSAGE)) { //nothing to do } else if (this.getTypeMessages().equalsIgnoreCase(TYPE_RETURN_ACTION_ERROR_MESSAGE)) { ((ValidationAware) action).addActionError(errorMessage); } else if (this.getTypeMessages().equalsIgnoreCase(TYPE_RETURN_ACTION_MESSAGE)) { ((ValidationAware) action).addActionMessage(message); } else { LOG.warn("Invalid message type : {}", this.getTypeMessages()); } } else { LOG.warn(errorMessage); } return INVALID_TOKEN_CODE; }
@Override protected String handleInvalidToken(ActionInvocation invocation) throws Exception { Object action = invocation.getAction(); String errorMessage = this.getCustomMessage(invocation, "struts.messages.invalid.token", "The form has already been processed or no token was supplied, please try again."); String message = this.getCustomMessage(invocation, "struts.messages.invalid.token.message", "Stop double-submission of forms."); if (action instanceof ValidationAware) { if (null == this.getTypeMessages() || this.getTypeMessages().equalsIgnoreCase(TYPE_RETURN_NONE_MESSAGE)) { //nothing to do } else if (this.getTypeMessages().equalsIgnoreCase(TYPE_RETURN_ACTION_ERROR_MESSAGE)) { ((ValidationAware) action).addActionError(errorMessage); } else if (this.getTypeMessages().equalsIgnoreCase(TYPE_RETURN_ACTION_MESSAGE)) { ((ValidationAware) action).addActionMessage(message); } else { LOG.warn("Invalid message type : {}", this.getTypeMessages()); } } else { LOG.warn(errorMessage); } return INVALID_TOKEN_CODE; }