Search in sources :

Example 71 with ActionErrors

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

the class ImportTransactionsActionForm method validate.

/**
     * Check to make sure the client hasn't exceeded the maximum allowed upload
     * size inside of this validate method.
     */
@Override
public ActionErrors validate(@SuppressWarnings("unused") ActionMapping mapping, HttpServletRequest request) {
    ActionErrors errors = new ActionErrors();
    // Do not validate if validation is not for upload
    if (!request.getParameter("method").equals("upload")) {
        // Using validate in Action classes creates confusion.
        if (request.getAttribute("methodCalled") != null && request.getAttribute("methodCalled").equals("upload")) {
            request.setAttribute(Globals.ERROR_KEY, request.getAttribute("uploadErrors"));
        }
        return null;
    }
    request.setAttribute("methodCalled", request.getParameter("method"));
    request.setAttribute("uploadErrors", errors);
    if ((importPluginName != null) && (importPluginName.length() < 1)) {
        errors.add("importPluginName", new ActionMessage("errors.importexport.mandatory_selectbox"));
    }
    // has the maximum length been exceeded?
    Boolean maxLengthExceeded = (Boolean) request.getAttribute(MultipartRequestHandler.ATTRIBUTE_MAX_LENGTH_EXCEEDED);
    if ((maxLengthExceeded != null) && (maxLengthExceeded.booleanValue())) {
        errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("errors.importexport.toobig"));
    } else if ((importTransactionsFile != null) && (importTransactionsFile.getFileName().length() < 1)) {
        errors.add("importTransactionsFile", new ActionMessage("errors.importexport.mandatory_file"));
    }
    try {
        // FIXME - remove call to service facade from form.
        if (importTransactionsFile.getFileName() != null && ApplicationContextProvider.getBean(ImportTransactionsServiceFacade.class).isAlreadyImported(importTransactionsFile.getFileName())) {
            errors.add("importTransactionsFile", new ActionMessage("errors.importexport.already_submitted"));
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return errors;
}
Also used : ActionMessage(org.apache.struts.action.ActionMessage) ActionErrors(org.apache.struts.action.ActionErrors)

Example 72 with ActionErrors

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

the class LookupOptionsActionForm method validate.

@Override
public ActionErrors validate(ActionMapping mapping, HttpServletRequest request) {
    logger.debug("Inside validate method");
    String method = request.getParameter(Methods.method.toString());
    request.setAttribute(Constants.CURRENTFLOWKEY, request.getParameter(Constants.CURRENTFLOWKEY));
    ActionErrors errors = new ActionErrors();
    if (method.equals(Methods.update.toString())) {
        errors = super.validate(mapping, request);
        request.setAttribute(ConfigurationConstants.LOOKUP_TYPE, request.getParameter(ConfigurationConstants.LOOKUP_TYPE));
        if (// check for duplicate
        errors.isEmpty()) {
            String entity = request.getParameter(ConfigurationConstants.ENTITY);
            checkForDuplicate(entity, errors);
        }
    } else if (method.equals(Methods.addEditLookupOption.toString())) {
        String entity = request.getParameter(ConfigurationConstants.ENTITY);
        String addOrEdit = request.getParameter(ConfigurationConstants.ADD_OR_EDIT);
        if (addOrEdit.equals("edit") && !itemIsSelectedInList(entity)) {
            String entityType = getEntityType(entity, request);
            addError(errors, entity, "errors.selectvalue", new String[] { entityType });
            setHiddenFields(request);
        }
    }
    if (!errors.isEmpty()) {
        request.setAttribute(Methods.method.toString(), method);
    }
    logger.debug("outside validate method");
    return errors;
}
Also used : ActionErrors(org.apache.struts.action.ActionErrors)

Example 73 with ActionErrors

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

the class BulkEntryActionForm method validate.

@Override
public ActionErrors validate(ActionMapping mapping, HttpServletRequest request) {
    logger.debug("BulkEntryActionForm.validate");
    request.setAttribute(Constants.CURRENTFLOWKEY, request.getParameter(Constants.CURRENTFLOWKEY));
    ActionErrors errors = new ActionErrors();
    if (request.getParameter(CollectionSheetEntryConstants.METHOD).equalsIgnoreCase(CollectionSheetEntryConstants.GETMETHOD)) {
        java.sql.Date meetingDate = null;
        try {
            Object lastMeetingDate = SessionUtils.getAttribute("LastMeetingDate", request);
            if (lastMeetingDate != null) {
                meetingDate = new java.sql.Date(((java.util.Date) lastMeetingDate).getTime());
            }
            short isCenterHierarchyExists = (Short) SessionUtils.getAttribute(CollectionSheetEntryConstants.ISCENTERHIERARCHYEXISTS, request);
            return mandatoryCheck(meetingDate, getUserContext(request), isCenterHierarchyExists);
        } catch (PageExpiredException e) {
            errors.add(ExceptionConstants.PAGEEXPIREDEXCEPTION, new ActionMessage(ExceptionConstants.PAGEEXPIREDEXCEPTION));
        }
    }
    return errors;
}
Also used : PageExpiredException(org.mifos.framework.exceptions.PageExpiredException) ActionMessage(org.apache.struts.action.ActionMessage) ActionErrors(org.apache.struts.action.ActionErrors) Date(java.sql.Date) Date(java.sql.Date)

Example 74 with ActionErrors

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

the class MeetingActionForm method validate.

@Override
public ActionErrors validate(ActionMapping mapping, HttpServletRequest request) {
    String method = request.getParameter("method");
    request.setAttribute(Constants.CURRENTFLOWKEY, request.getParameter(Constants.CURRENTFLOWKEY));
    ActionErrors errors = new ActionErrors();
    try {
        errors = validateFields(request, method);
    } catch (ApplicationException ae) {
        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);
    }
    return errors;
}
Also used : ApplicationException(org.mifos.framework.exceptions.ApplicationException) ActionMessage(org.apache.struts.action.ActionMessage) ActionErrors(org.apache.struts.action.ActionErrors)

Example 75 with ActionErrors

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

the class MeetingActionForm method validateMeeting.

private ActionErrors validateMeeting() {
    ActionErrors errors = new ActionErrors();
    if (getRecurrenceType() == null) {
        errors.add(MeetingConstants.INVALID_RECURRENCETYPE, new ActionMessage(MeetingConstants.INVALID_RECURRENCETYPE));
    } else if (getRecurrenceType().equals(RecurrenceType.WEEKLY)) {
        validateWeeklyMeeting(errors);
    } else if (getRecurrenceType().equals(RecurrenceType.MONTHLY)) {
        validateMonthlyMeeting(errors);
    } else if (getRecurrenceType().equals(RecurrenceType.DAILY)) {
        validateDailyMeeting(errors);
    }
    if (StringUtils.isBlank(getMeetingPlace())) {
        errors.add(MeetingConstants.INVALID_MEETINGPLACE, new ActionMessage(MeetingConstants.INVALID_MEETINGPLACE));
    }
    validateMeetingStartDate(errors);
    return errors;
}
Also used : ActionMessage(org.apache.struts.action.ActionMessage) 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