Search in sources :

Example 1 with ActionErrors

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

the class AbstractValidateActionForm method execute.

// ---------------------------------------------------------- Public Methods
/**
     * <p>Validate the properties of the form bean for this request.  If there
     * are any validation errors, execute the child commands in our chain;
     * otherwise, proceed normally.</p>
     *
     * @param actionCtx The <code>Context</code> for the current request
     * @return <code>false</code> so that processing continues, if there are
     *         no validation errors; otherwise <code>true</code>
     * @throws Exception if thrown by the Action class
     */
public boolean execute(ActionContext actionCtx) throws Exception {
    // Set form valid until found otherwise
    actionCtx.setFormValid(Boolean.TRUE);
    // Is there a form bean for this request?
    ActionForm actionForm = actionCtx.getActionForm();
    if (actionForm == null) {
        return false;
    }
    // Is validation disabled on this request?
    ActionConfig actionConfig = actionCtx.getActionConfig();
    if (!actionConfig.getValidate()) {
        return false;
    }
    // Was this request cancelled?
    if (isCancelled(actionCtx, actionConfig)) {
        if (LOG.isDebugEnabled()) {
            LOG.debug(" Cancelled transaction, skipping validation");
        }
        return false;
    }
    // Call the validate() method of this form bean
    ActionErrors errors = validate(actionCtx, actionConfig, actionForm);
    // If there were no errors, proceed normally
    if ((errors == null) || (errors.isEmpty())) {
        return false;
    }
    // Flag the validation failure and proceed
    /* NOTE: Is there any concern that there might have already
         * been errors, or that other errors might be coming?
         */
    actionCtx.saveErrors(errors);
    actionCtx.setFormValid(Boolean.FALSE);
    return false;
}
Also used : ActionConfig(org.apache.struts.config.ActionConfig) ActionForm(org.apache.struts.action.ActionForm) ActionErrors(org.apache.struts.action.ActionErrors)

Example 2 with ActionErrors

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

the class ValidateActionForm method validate.

// ------------------------------------------------------- Protected Methods
/**
     * <p>Call the <code>validate()</code> method of the specified form bean,
     * and return the resulting <code>ActionErrors</code> object.</p>
     *
     * @param context    The context for this request
     * @param actionForm The form bean for this request
     */
protected ActionErrors validate(ActionContext context, ActionConfig actionConfig, ActionForm actionForm) {
    ServletActionContext saContext = (ServletActionContext) context;
    ActionErrors errors = (actionForm.validate((ActionMapping) actionConfig, saContext.getRequest()));
    // Special handling for multipart request
    if ((errors != null) && !errors.isEmpty()) {
        if (actionForm.getMultipartRequestHandler() != null) {
            if (log.isTraceEnabled()) {
                log.trace("  Rolling back multipart request");
            }
            actionForm.getMultipartRequestHandler().rollback();
        }
    }
    return errors;
}
Also used : ActionMapping(org.apache.struts.action.ActionMapping) ServletActionContext(org.apache.struts.chain.contexts.ServletActionContext) ActionErrors(org.apache.struts.action.ActionErrors)

Example 3 with ActionErrors

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

the class EditStatusAction method captureQuestionResponses.

@TransactionDemarcate(joinToken = true)
public ActionForward captureQuestionResponses(final ActionMapping mapping, final ActionForm form, final HttpServletRequest request, @SuppressWarnings("unused") final HttpServletResponse response) throws Exception {
    request.setAttribute(METHODCALLED, "captureQuestionResponses");
    ActionErrors errors = loanQuestionnaire.validateResponses(request, (EditStatusActionForm) form);
    if (errors != null && !errors.isEmpty()) {
        addErrors(request, errors);
        return mapping.findForward(ActionForwards.captureQuestionResponses.toString());
    }
    return loanQuestionnaire.rejoinFlow(mapping);
}
Also used : ActionErrors(org.apache.struts.action.ActionErrors) TransactionDemarcate(org.mifos.framework.util.helpers.TransactionDemarcate)

Example 4 with ActionErrors

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

the class SavingsClosureAction method captureQuestionResponses.

@TransactionDemarcate(joinToken = true)
public ActionForward captureQuestionResponses(final ActionMapping mapping, final ActionForm form, final HttpServletRequest request, @SuppressWarnings("unused") final HttpServletResponse response) throws Exception {
    request.setAttribute(METHODCALLED, "captureQuestionResponses");
    ActionErrors errors = closeSavingsQuestionnaire.validateResponses(request, (SavingsClosureActionForm) form);
    if (errors != null && !errors.isEmpty()) {
        addErrors(request, errors);
        return mapping.findForward(ActionForwards.captureQuestionResponses.toString());
    }
    return closeSavingsQuestionnaire.rejoinFlow(mapping);
}
Also used : ActionErrors(org.apache.struts.action.ActionErrors) TransactionDemarcate(org.mifos.framework.util.helpers.TransactionDemarcate)

Example 5 with ActionErrors

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

the class SavingsActionForm method validate.

@Override
public ActionErrors validate(ActionMapping mapping, HttpServletRequest request) {
    String method = request.getParameter("method");
    ActionErrors errors = new ActionErrors();
    String mandatoryAmount = getLocalizedMessage(SavingsConstants.MANDATORY_AMOUNT_FOR_DEPOSIT_KEY);
    request.setAttribute(Constants.CURRENTFLOWKEY, request.getParameter(Constants.CURRENTFLOWKEY));
    if (method.equals("getPrdOfferings") || method.equals("create") || method.equals("edit") || method.equals("update") || method.equals("get") || method.equals("validate")) {
    } else {
        errors.add(super.validate(mapping, request));
        if (method.equals("preview") || method.equals("editPreview")) {
            try {
                SavingsOfferingBO savingsOffering = (SavingsOfferingBO) SessionUtils.getAttribute(SavingsConstants.PRDOFFERING, request);
                if (savingsOffering.getSavingsType().getId().equals(SavingsType.MANDATORY.getValue()) && StringUtils.isBlank(getRecommendedAmount())) {
                    // check for mandatory amount
                    errors.add(SavingsConstants.MANDATORY, new ActionMessage(SavingsConstants.MANDATORY, mandatoryAmount));
                }
                if (StringUtils.isNotBlank(getRecommendedAmount())) {
                    if (savingsOffering.getSavingsType().equals(SavingsType.MANDATORY)) {
                        validateAmount(getRecommendedAmount(), SavingsConstants.MANDATORY_AMOUNT_FOR_DEPOSIT_KEY, errors);
                    } else {
                        validateAmount(getRecommendedAmount(), SavingsConstants.RECOMMENDED_AMOUNT_FOR_DEPOSIT_KEY, errors);
                    }
                }
                validateCustomFields(request, errors);
            } catch (PageExpiredException e) {
                errors.add(SavingsConstants.MANDATORY, new ActionMessage(SavingsConstants.MANDATORY, mandatoryAmount));
            }
        }
    }
    if (!errors.isEmpty()) {
        request.setAttribute(Globals.ERROR_KEY, errors);
        request.setAttribute("methodCalled", method);
    }
    return errors;
}
Also used : SavingsOfferingBO(org.mifos.accounts.productdefinition.business.SavingsOfferingBO) ActionMessage(org.apache.struts.action.ActionMessage) PageExpiredException(org.mifos.framework.exceptions.PageExpiredException) ActionErrors(org.apache.struts.action.ActionErrors)

Aggregations

ActionErrors (org.apache.struts.action.ActionErrors)144 ActionMessage (org.apache.struts.action.ActionMessage)68 InvalidDateException (org.mifos.application.admin.servicefacade.InvalidDateException)20 Locale (java.util.Locale)19 ResourceBundle (java.util.ResourceBundle)13 TransactionDemarcate (org.mifos.framework.util.helpers.TransactionDemarcate)12 Test (org.junit.Test)9 DoubleConversionResult (org.mifos.framework.util.helpers.DoubleConversionResult)7 Date (java.sql.Date)5 ApplicationException (org.mifos.framework.exceptions.ApplicationException)5 PageExpiredException (org.mifos.framework.exceptions.PageExpiredException)4 ReportsPersistence (org.mifos.reports.persistence.ReportsPersistence)4 DateTime (org.joda.time.DateTime)3 PaymentDataHtmlBean (org.mifos.accounts.loan.struts.uihelpers.PaymentDataHtmlBean)3 ReportsCategoryBO (org.mifos.reports.business.ReportsCategoryBO)3 Problem (cn.edu.zju.acm.onlinejudge.bean.Problem)2 ArrayList (java.util.ArrayList)2 ServletContext (javax.servlet.ServletContext)2 HttpServletRequest (javax.servlet.http.HttpServletRequest)2 HttpSession (javax.servlet.http.HttpSession)2