Search in sources :

Example 91 with ActionMessage

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

the class ClientCustActionForm method validateFamilyOneSpouseOrFather.

public void validateFamilyOneSpouseOrFather(ActionErrors errors) {
    int spouseCount = 0;
    int fatherCount = 0;
    for (int row = 0; row < familyRelationship.size(); row++) {
        if (familyRelationship.get(row) != null) {
            if (familyRelationship.get(row) == 2) {
                fatherCount++;
            }
            if (familyRelationship.get(row) == 1) {
                spouseCount++;
            }
        }
    }
    if (spouseCount > 1) {
        errors.add(ClientConstants.INVALID_NUMBER_OF_SPOUSES, new ActionMessage(ClientConstants.INVALID_NUMBER_OF_SPOUSES));
    }
    if (fatherCount > 1) {
        errors.add(ClientConstants.INVALID_NUMBER_OF_FATHERS, new ActionMessage(ClientConstants.INVALID_NUMBER_OF_FATHERS));
    }
}
Also used : ActionMessage(org.apache.struts.action.ActionMessage)

Example 92 with ActionMessage

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

the class ClientCustActionForm method validateTrained.

@Override
protected void validateTrained(HttpServletRequest request, ActionErrors errors) {
    super.validateTrained(request, errors);
    try {
        Locale locale = getUserContext(request).getPreferredLocale();
        Date trainedDate = getTrainedDateValue(locale);
        Date dob = getDateFromString(getDateOfBirth(), locale);
        if (trainedDate != null && dob != null && DateUtils.dateFallsBeforeDate(trainedDate, dob)) {
            errors.add(CustomerConstants.TRAINED_DATE_BEFORE_DOB, new ActionMessage(CustomerConstants.TRAINED_DATE_BEFORE_DOB, getDateOfBirth()));
        }
    } catch (InvalidDateException ex) {
    //already validated in super
    }
}
Also used : Locale(java.util.Locale) InvalidDateException(org.mifos.application.admin.servicefacade.InvalidDateException) ActionMessage(org.apache.struts.action.ActionMessage) Date(java.util.Date)

Example 93 with ActionMessage

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

the class CustSearchAction method mainSearch.

@TransactionDemarcate(joinToken = true)
public ActionForward mainSearch(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
    CustSearchActionForm actionForm = (CustSearchActionForm) form;
    Short officeId = getShortValue(actionForm.getOfficeId());
    String searchString = actionForm.getSearchString();
    UserContext userContext = (UserContext) SessionUtils.getAttribute(Constants.USERCONTEXT, request.getSession());
    super.search(mapping, form, request, response);
    if (searchString == null || searchString.equals("")) {
        ActionErrors errors = new ActionErrors();
        errors.add(CustomerSearchConstants.NAMEMANDATORYEXCEPTION, new ActionMessage(CustomerSearchConstants.NAMEMANDATORYEXCEPTION));
        request.setAttribute(Globals.ERROR_KEY, errors);
        return mapping.findForward(ActionForwards.mainSearch_success.toString());
    }
    if (officeId != null && officeId != 0) {
        addSeachValues(searchString, officeId.toString(), new OfficePersistence().getOffice(officeId).getOfficeName(), request);
    } else {
        addSeachValues(searchString, officeId.toString(), new OfficePersistence().getOffice(userContext.getBranchId()).getOfficeName(), request);
    }
    searchString = SearchUtils.normalizeSearchString(searchString);
    if (searchString.equals("")) {
        throw new CustomerException(CustomerSearchConstants.NAMEMANDATORYEXCEPTION);
    }
    if (actionForm.getFilters() == null) {
        actionForm.setFilters(new SearchFiltersDto());
    }
    QueryResult customerSearchResult = new CustomerPersistence().search(searchString, officeId, userContext.getId(), userContext.getBranchId(), actionForm.getFilters());
    SessionUtils.setQueryResultAttribute(Constants.SEARCH_RESULTS, customerSearchResult, request);
    return mapping.findForward(ActionForwards.mainSearch_success.toString());
}
Also used : CustomerException(org.mifos.customers.exceptions.CustomerException) QueryResult(org.mifos.framework.hibernate.helper.QueryResult) CustSearchActionForm(org.mifos.customers.struts.actionforms.CustSearchActionForm) UserContext(org.mifos.security.util.UserContext) ActionMessage(org.apache.struts.action.ActionMessage) SearchFiltersDto(org.mifos.dto.screen.SearchFiltersDto) CustomerPersistence(org.mifos.customers.persistence.CustomerPersistence) OfficePersistence(org.mifos.customers.office.persistence.OfficePersistence) ActionErrors(org.apache.struts.action.ActionErrors) TransactionDemarcate(org.mifos.framework.util.helpers.TransactionDemarcate)

Example 94 with ActionMessage

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

the class GroupCustActionForm method validateFields.

@Override
protected ActionErrors validateFields(HttpServletRequest request, String method) throws ApplicationException {
    ActionErrors errors = new ActionErrors();
    try {
        if (method.equals(Methods.previewManage.toString())) {
            validateName(errors);
            validateTrained(request, errors);
            validateConfigurableMandatoryFields(request, errors, EntityType.GROUP);
            validateCustomFieldsForCustomers(request, errors);
        } else if (method.equals(Methods.preview.toString()) || method.equals(Methods.previewOnly.toString())) {
            validateName(errors);
            validateLO(errors);
            validateFormedByPersonnel(errors);
            validateTrained(request, errors);
            validateConfigurableMandatoryFields(request, errors, EntityType.GROUP);
            validateCustomFieldsForCustomers(request, errors);
            validateFees(request, errors);
        }
    } catch (ApplicationException ae) {
        // Discard other errors (is that right?)
        ae.printStackTrace();
        errors = new ActionErrors();
        errors.add(ae.getKey(), new ActionMessage(ae.getKey(), ae.getValues()));
    }
    if (!errors.isEmpty()) {
        request.setAttribute(GroupConstants.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 95 with ActionMessage

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

the class PersonActionForm method validate.

@Override
public ActionErrors validate(ActionMapping mapping, HttpServletRequest request) {
    ActionErrors errors = new ActionErrors();
    String method = request.getParameter("method");
    request.setAttribute(Constants.CURRENTFLOWKEY, request.getParameter(Constants.CURRENTFLOWKEY));
    request.getSession().setAttribute(Constants.CURRENTFLOWKEY, request.getParameter(Constants.CURRENTFLOWKEY));
    if (method.equals(Methods.preview.toString())) {
        handleCreatePreviewValidations(errors, request);
    }
    if (method.equals(Methods.previewManage.toString())) {
        handleManagePreviewValidations(errors, request);
    }
    if (method.equals(Methods.search.toString())) {
        if (StringUtils.isBlank(searchString)) {
            try {
                cleanUpSearch(request);
            } catch (PageExpiredException e) {
                errors.add(ExceptionConstants.PAGEEXPIREDEXCEPTION, new ActionMessage(ExceptionConstants.PAGEEXPIREDEXCEPTION));
            }
            errors.add(PersonnelConstants.NO_SEARCH_STRING, new ActionMessage(PersonnelConstants.NO_SEARCH_STRING));
        }
    }
    if (!errors.isEmpty()) {
        request.setAttribute(Globals.ERROR_KEY, errors);
        request.setAttribute("methodCalled", method);
        try {
            updateRoleLists(request);
        } 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)

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