Search in sources :

Example 56 with ActionMessage

use of org.apache.struts.action.ActionMessage in project head by mifos.

the class CustomerActionForm method validate.

@Override
public ActionErrors validate(ActionMapping mapping, HttpServletRequest request) {
    String method = request.getParameter("method");
    if (null == request.getAttribute(Constants.CURRENTFLOWKEY)) {
        request.setAttribute(Constants.CURRENTFLOWKEY, request.getParameter(Constants.CURRENTFLOWKEY));
    }
    ActionErrors errors = null;
    try {
        errors = validateFields(request, method);
    } catch (ApplicationException ae) {
        errors = new ActionErrors();
        errors.add(ae.getKey(), new ActionMessage(ae.getKey(), ae.getValues()));
    }
    if (null != errors && !errors.isEmpty()) {
        request.setAttribute(Globals.ERROR_KEY, errors);
        request.setAttribute("methodCalled", method);
    }
    errors.add(super.validate(mapping, request));
    return errors;
}
Also used : ApplicationException(org.mifos.framework.exceptions.ApplicationException) ActionMessage(org.apache.struts.action.ActionMessage) ActionErrors(org.apache.struts.action.ActionErrors)

Example 57 with ActionMessage

use of org.apache.struts.action.ActionMessage in project head by mifos.

the class ClientCustActionFormTest method testMoreThanMaximumAge.

public void testMoreThanMaximumAge() throws Exception {
    if (!ClientRules.isAgeCheckEnabled()) {
        ClientRules.setMaximumAgeForNewClient(60);
        ClientRules.setMinimumAgeForNewClient(18);
        ClientRules.setAgeCheckEnabled(true);
        ClientRules.setAgeCheckWarningInsteadOfError(false);
    }
    form.setDateOfBirthDD("2");
    form.setDateOfBirthMM("2");
    form.setDateOfBirthYY("1940");
    form.validateDateOfBirth(errors);
    Assert.assertEquals(1, errors.size());
    ActionMessage message = (ActionMessage) errors.get().next();
    Assert.assertEquals(ClientConstants.INVALID_AGE, message.getKey());
}
Also used : ActionMessage(org.apache.struts.action.ActionMessage)

Example 58 with ActionMessage

use of org.apache.struts.action.ActionMessage in project head by mifos.

the class ClientCustActionFormTest method testFutureDate.

public void testFutureDate() throws Exception {
    form.setDateOfBirthDD("6");
    form.setDateOfBirthMM("12");
    form.setDateOfBirthYY("2108");
    form.validateDateOfBirth(errors);
    Assert.assertEquals(1, errors.size());
    ActionMessage message = (ActionMessage) errors.get().next();
    Assert.assertEquals(ClientConstants.FUTURE_DOB_EXCEPTION, message.getKey());
}
Also used : ActionMessage(org.apache.struts.action.ActionMessage)

Example 59 with ActionMessage

use of org.apache.struts.action.ActionMessage in project sonarqube by SonarSource.

the class Resources method getActionMessage.

/**
     * Gets the <code>ActionMessage</code> based on the
     * <code>ValidatorAction</code> message and the <code>Field</code>'s arg
     * objects.
     *
     * @param validator the Validator
     * @param request   the servlet request
     * @param va        Validator action
     * @param field     the validator Field
     */
public static ActionMessage getActionMessage(Validator validator, HttpServletRequest request, ValidatorAction va, Field field) {
    Msg msg = field.getMessage(va.getName());
    if ((msg != null) && !msg.isResource()) {
        return new ActionMessage(msg.getKey(), false);
    }
    String msgKey = null;
    String msgBundle = null;
    if (msg == null) {
        msgKey = va.getMsg();
    } else {
        msgKey = msg.getKey();
        msgBundle = msg.getBundle();
    }
    if ((msgKey == null) || (msgKey.length() == 0)) {
        return new ActionMessage("??? " + va.getName() + "." + field.getProperty() + " ???", false);
    }
    ServletContext application = (ServletContext) validator.getParameterValue(SERVLET_CONTEXT_PARAM);
    MessageResources messages = getMessageResources(application, request, msgBundle);
    Locale locale = RequestUtils.getUserLocale(request, null);
    Arg[] args = field.getArgs(va.getName());
    String[] argValues = getArgValues(application, request, messages, locale, args);
    ActionMessage actionMessage = null;
    if (msgBundle == null) {
        actionMessage = new ActionMessage(msgKey, argValues);
    } else {
        String message = messages.getMessage(locale, msgKey, argValues);
        actionMessage = new ActionMessage(message, false);
    }
    return actionMessage;
}
Also used : Msg(org.apache.commons.validator.Msg) Locale(java.util.Locale) MessageResources(org.apache.struts.util.MessageResources) Arg(org.apache.commons.validator.Arg) ActionMessage(org.apache.struts.action.ActionMessage) ServletContext(javax.servlet.ServletContext)

Example 60 with ActionMessage

use of org.apache.struts.action.ActionMessage in project sonarqube by SonarSource.

the class ErrorsTag method doStartTag.

// ------------------------------------------------------- Public Methods
/**
     * Render the specified error messages if there are any.
     *
     * @throws JspException if a JSP exception has occurred
     */
public int doStartTag() throws JspException {
    // Were any error messages specified?
    ActionMessages errors = null;
    try {
        errors = TagUtils.getInstance().getActionMessages(pageContext, name);
    } catch (JspException e) {
        TagUtils.getInstance().saveException(pageContext, e);
        throw e;
    }
    if ((errors == null) || errors.isEmpty()) {
        return (EVAL_BODY_INCLUDE);
    }
    boolean headerPresent = TagUtils.getInstance().present(pageContext, bundle, locale, getHeader());
    boolean footerPresent = TagUtils.getInstance().present(pageContext, bundle, locale, getFooter());
    boolean prefixPresent = TagUtils.getInstance().present(pageContext, bundle, locale, getPrefix());
    boolean suffixPresent = TagUtils.getInstance().present(pageContext, bundle, locale, getSuffix());
    // Render the error messages appropriately
    StringBuffer results = new StringBuffer();
    boolean headerDone = false;
    String message = null;
    Iterator reports = (property == null) ? errors.get() : errors.get(property);
    while (reports.hasNext()) {
        ActionMessage report = (ActionMessage) reports.next();
        if (!headerDone) {
            if (headerPresent) {
                message = TagUtils.getInstance().message(pageContext, bundle, locale, getHeader());
                results.append(message);
            }
            headerDone = true;
        }
        if (prefixPresent) {
            message = TagUtils.getInstance().message(pageContext, bundle, locale, getPrefix());
            results.append(message);
        }
        if (report.isResource()) {
            message = TagUtils.getInstance().message(pageContext, bundle, locale, report.getKey(), report.getValues());
        } else {
            message = report.getKey();
        }
        if (message != null) {
            results.append(message);
        }
        if (suffixPresent) {
            message = TagUtils.getInstance().message(pageContext, bundle, locale, getSuffix());
            results.append(message);
        }
    }
    if (headerDone && footerPresent) {
        message = TagUtils.getInstance().message(pageContext, bundle, locale, getFooter());
        results.append(message);
    }
    TagUtils.getInstance().write(pageContext, results.toString());
    return (EVAL_BODY_INCLUDE);
}
Also used : JspException(javax.servlet.jsp.JspException) ActionMessages(org.apache.struts.action.ActionMessages) Iterator(java.util.Iterator) ActionMessage(org.apache.struts.action.ActionMessage)

Aggregations

ActionMessage (org.apache.struts.action.ActionMessage)146 ActionErrors (org.apache.struts.action.ActionErrors)68 ActionMessages (org.apache.struts.action.ActionMessages)31 ResourceBundle (java.util.ResourceBundle)29 InvalidDateException (org.mifos.application.admin.servicefacade.InvalidDateException)22 Locale (java.util.Locale)18 JspException (javax.servlet.jsp.JspException)11 Iterator (java.util.Iterator)10 ActionForward (org.apache.struts.action.ActionForward)9 AbstractContest (cn.edu.zju.acm.onlinejudge.bean.AbstractContest)8 List (java.util.List)8 Problem (cn.edu.zju.acm.onlinejudge.bean.Problem)7 ArrayList (java.util.ArrayList)7 DoubleConversionResult (org.mifos.framework.util.helpers.DoubleConversionResult)7 UserProfile (cn.edu.zju.acm.onlinejudge.bean.UserProfile)6 Date (java.sql.Date)6 PageExpiredException (org.mifos.framework.exceptions.PageExpiredException)6 ApplicationException (org.mifos.framework.exceptions.ApplicationException)5 UserPersistence (cn.edu.zju.acm.onlinejudge.persistence.UserPersistence)4 UserSecurity (cn.edu.zju.acm.onlinejudge.security.UserSecurity)4