use of org.apache.struts.action.ActionErrors in project head by mifos.
the class LoginFilter method doFilter.
/**
* This function implements the login filter it checks if user is not login
* it forces the user to login by redirecting him to login page
*/
@Override
public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException, ServletException {
HttpServletRequest request = (HttpServletRequest) req;
request.setCharacterEncoding("UTF-8");
String complUri = request.getRequestURI();
int index = complUri.lastIndexOf("/");
String uri = complUri.substring(index + 1);
try {
if (uri == null || uri.equalsIgnoreCase(LoginConstants.LOGINPAGEURI) || uri.equalsIgnoreCase(LoginConstants.LOGINACTION)) {
logger.debug("Inside Filter uri is for login page");
chain.doFilter(req, res);
} else {
if (request.getSession(false) == null) {
logger.debug("Inside Filter session is null");
ActionErrors error = new ActionErrors();
error.add(LoginConstants.SESSIONTIMEOUT, new ActionMessage(LoginConstants.SESSIONTIMEOUT));
request.setAttribute(Globals.ERROR_KEY, error);
request.getRequestDispatcher(LoginConstants.LOGINPAGEURI).forward(req, res);
// ((HttpServletResponse)res).sendRedirect(request.getContextPath()+LoginConstants.LOGINPAGEURI);
return;
}
UserContext userContext = (UserContext) request.getSession(false).getAttribute(Constants.USERCONTEXT);
if (null == userContext || null == userContext.getId()) {
// send back to login page with error message
((HttpServletResponse) res).sendRedirect(request.getContextPath() + LoginConstants.LOGINPAGEURI);
return;
} else {
((HttpServletRequest) req).getSession(false).setAttribute(Constants.RANDOMNUM, new Random().nextLong());
chain.doFilter(req, res);
}
}
} catch (IllegalStateException ise) {
logger.error("Inside Filter ISE" + ise.getMessage());
ActionMessage error = new ActionMessage(LoginConstants.IllEGALSTATE);
request.setAttribute(Globals.ERROR_KEY, error);
((HttpServletResponse) res).sendRedirect(request.getContextPath() + LoginConstants.LOGINPAGEURI);
} finally {
StaticHibernateUtil.closeSession();
}
}
use of org.apache.struts.action.ActionErrors in project head by mifos.
the class FeeActionFormTest method isAmountValid.
private boolean isAmountValid(FeeActionForm form) {
ActionErrors errors = new ActionErrors();
form.validateAmount(errors, locale);
return errors.size() == 0;
}
use of org.apache.struts.action.ActionErrors in project head by mifos.
the class PersonnelSettingsActionForm method validate.
@Override
public ActionErrors validate(ActionMapping mapping, HttpServletRequest request) {
ActionErrors errors = new ActionErrors();
String method = request.getParameter(Methods.method.toString());
if (method.equals(Methods.preview.toString())) {
if (StringUtils.isBlank(getFirstName())) {
addError(errors, PersonnelConstants.FIRSTNAME, PersonnelConstants.ERRORMANDATORY, PersonnelConstants.FIRST_NAME);
} else if (getFirstName().length() > PersonnelConstants.PERSONNELLENGTH) {
addError(errors, PersonnelConstants.FIRSTNAME, PersonnelConstants.MAXIMUM_LENGTH, PersonnelConstants.FIRST_NAME, PersonnelConstants.PERSONNELNAMELENGTH);
}
if (StringUtils.isBlank(getLastName())) {
addError(errors, PersonnelConstants.LASTNAME, PersonnelConstants.ERRORMANDATORY, PersonnelConstants.LAST_NAME);
} else if (getLastName().length() > PersonnelConstants.PERSONNELLENGTH) {
addError(errors, PersonnelConstants.LASTNAME, PersonnelConstants.MAXIMUM_LENGTH, PersonnelConstants.LAST_NAME, PersonnelConstants.PERSONNELNAMELENGTH);
}
if (StringUtils.isBlank(getGender())) {
addError(errors, PersonnelConstants.GENDERVALUE, PersonnelConstants.MANDATORYSELECT, PersonnelConstants.GENDERVALUE);
}
if (getDisplayName().length() > PersonnelConstants.PERSONNELDISPLAYNAMELENGTH) {
addError(errors, PersonnelConstants.DISPLAYNAME, PersonnelConstants.MAXIMUM_LENGTH, PersonnelConstants.DISPLAY_NAME, PersonnelConstants.PERSONNELDISPLAYLENGTH);
}
validateEmail(errors);
}
if (!method.equals(Methods.validate.toString())) {
request.setAttribute("methodCalled", method);
}
return errors;
}
use of org.apache.struts.action.ActionErrors 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());
}
use of org.apache.struts.action.ActionErrors in project head by mifos.
the class CenterCustActionForm method validateFields.
/*
* Validation is done in the order that the fields appear on the UI.
*
* @see org.mifos.customers.struts.actionforms.CustomerActionForm#
* validateFields(javax.servlet.http.HttpServletRequest, java.lang.String)
*/
@Override
protected ActionErrors validateFields(HttpServletRequest request, String method) throws ApplicationException {
ActionErrors errors = new ActionErrors();
if (method.equals(Methods.preview.toString())) {
validateName(errors);
validateLO(errors);
validateMeeting(request, errors);
} else if (method.equals(Methods.editPreview.toString())) {
validateName(errors);
CenterBO center = (CenterBO) SessionUtils.getAttribute(Constants.BUSINESS_KEY, request);
if (center.isActive()) {
validateLO(errors);
}
}
if (method.equals(Methods.preview.toString()) || method.equals(Methods.editPreview.toString())) {
validateMfiJoiningDate(request, errors);
validateConfigurableMandatoryFields(request, errors, EntityType.CENTER);
validateCustomFieldsForCustomers(request, errors);
}
// fees are only editable in preview and come last
if (method.equals(Methods.preview.toString())) {
validateFees(request, errors);
}
return errors;
}
Aggregations