Search in sources :

Example 66 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 67 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 68 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 69 with ActionErrors

use of org.apache.struts.action.ActionErrors in project zoj by licheng.

the class EditProblemAction method validate.

/**
     * Validates the form.
     * 
     * @param mapping
     *            the action mapping.
     * @param request
     *            the user request.
     * 
     * @return collection of validation errors.
     */
public ActionErrors validate(ProblemForm form, ContextAdapter context) throws Exception {
    ActionErrors errors = new ActionErrors();
    this.checkInteger(form.getProblemId(), 0, Integer.MAX_VALUE, "id", errors);
    String name = form.getName();
    String code = form.getCode();
    if (name == null || name.trim().length() == 0) {
        errors.add("name", new ActionMessage("ProblemForm.name.required"));
    }
    if (code == null || code.trim().length() == 0) {
        errors.add("code", new ActionMessage("ProblemForm.code.required"));
    }
    if (!form.isUseContestDefault()) {
        this.checkInteger(form.getTimeLimit(), 0, 3600, "timeLimit", errors);
        this.checkInteger(form.getMemoryLimit(), 0, 1024 * 1024, "memoryLimit", errors);
        this.checkInteger(form.getOutputLimit(), 0, 100 * 1024, "outputLimit", errors);
        this.checkInteger(form.getSubmissionLimit(), 0, 10 * 1024, "submissionLimit", errors);
    }
    List<Problem> problems = ContestManager.getInstance().getContestProblems(context.getContest().getId());
    /*for (Object obj : problems) {
            Problem p = (Problem) obj;
            if (!form.getProblemId().equals("" + p.getId()) && p.getTitle().equals(name)) {
                errors.add("name", new ActionMessage("ProblemForm.name.used"));
                break;
            }
        }*/
    for (Object obj : problems) {
        Problem p = (Problem) obj;
        if (!form.getProblemId().equals("" + p.getId()) && p.getCode().equals(code)) {
            errors.add("code", new ActionMessage("ProblemForm.code.used"));
            break;
        }
    }
    return errors;
}
Also used : ActionMessage(org.apache.struts.action.ActionMessage) Problem(cn.edu.zju.acm.onlinejudge.bean.Problem) ActionErrors(org.apache.struts.action.ActionErrors)

Example 70 with ActionErrors

use of org.apache.struts.action.ActionErrors in project zoj by licheng.

the class AddProblemAction method validate.

/**
     * Validates the form.
     * 
     * @param mapping
     *            the action mapping.
     * @param request
     *            the user request.
     * 
     * @return collection of validation errors.
     */
public ActionErrors validate(ProblemForm form, ContextAdapter context) throws Exception {
    ActionErrors errors = new ActionErrors();
    this.checkInteger(form.getProblemId(), 0, Integer.MAX_VALUE, "id", errors);
    String name = form.getName();
    String code = form.getCode();
    if (name == null || name.trim().length() == 0) {
        errors.add("name", new ActionMessage("ProblemForm.name.required"));
    }
    if (code == null || code.trim().length() == 0) {
        errors.add("code", new ActionMessage("ProblemForm.code.required"));
    }
    if (!form.isUseContestDefault()) {
        this.checkInteger(form.getTimeLimit(), 0, 3600, "timeLimit", errors);
        this.checkInteger(form.getMemoryLimit(), 0, 1024 * 1024, "memoryLimit", errors);
        this.checkInteger(form.getOutputLimit(), 0, 100 * 1024, "outputLimit", errors);
        this.checkInteger(form.getSubmissionLimit(), 0, 10 * 1024, "submissionLimit", errors);
    }
    List<Problem> problems = ContestManager.getInstance().getContestProblems(context.getContest().getId());
    /*for (Object problem : problems) {
            if (((Problem) problem).getTitle().equals(name)) {
                errors.add("name", new ActionMessage("ProblemForm.name.used"));
                break;
            }
        }*/
    for (Object problem : problems) {
        if (((Problem) problem).getCode().equals(code)) {
            errors.add("code", new ActionMessage("ProblemForm.code.used"));
            break;
        }
    }
    return errors;
}
Also used : ActionMessage(org.apache.struts.action.ActionMessage) Problem(cn.edu.zju.acm.onlinejudge.bean.Problem) 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