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;
}
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;
}
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;
}
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;
}
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;
}
Aggregations