use of org.apache.struts.action.ActionMessage in project head by mifos.
the class CustomerActionForm method validate.
@Override
public ActionErrors validate(ActionMapping mapping, HttpServletRequest request) {
String method = request.getParameter("method");
if (null == request.getAttribute(Constants.CURRENTFLOWKEY)) {
request.setAttribute(Constants.CURRENTFLOWKEY, request.getParameter(Constants.CURRENTFLOWKEY));
}
ActionErrors errors = null;
try {
errors = validateFields(request, method);
} catch (ApplicationException ae) {
errors = new ActionErrors();
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);
}
errors.add(super.validate(mapping, request));
return errors;
}
use of org.apache.struts.action.ActionMessage in project head by mifos.
the class ClientCustActionFormTest method testMoreThanMaximumAge.
public void testMoreThanMaximumAge() throws Exception {
if (!ClientRules.isAgeCheckEnabled()) {
ClientRules.setMaximumAgeForNewClient(60);
ClientRules.setMinimumAgeForNewClient(18);
ClientRules.setAgeCheckEnabled(true);
ClientRules.setAgeCheckWarningInsteadOfError(false);
}
form.setDateOfBirthDD("2");
form.setDateOfBirthMM("2");
form.setDateOfBirthYY("1940");
form.validateDateOfBirth(errors);
Assert.assertEquals(1, errors.size());
ActionMessage message = (ActionMessage) errors.get().next();
Assert.assertEquals(ClientConstants.INVALID_AGE, message.getKey());
}
use of org.apache.struts.action.ActionMessage in project head by mifos.
the class ClientCustActionFormTest method testFutureDate.
public void testFutureDate() throws Exception {
form.setDateOfBirthDD("6");
form.setDateOfBirthMM("12");
form.setDateOfBirthYY("2108");
form.validateDateOfBirth(errors);
Assert.assertEquals(1, errors.size());
ActionMessage message = (ActionMessage) errors.get().next();
Assert.assertEquals(ClientConstants.FUTURE_DOB_EXCEPTION, message.getKey());
}
use of org.apache.struts.action.ActionMessage in project sonarqube by SonarSource.
the class Resources method getActionMessage.
/**
* Gets the <code>ActionMessage</code> based on the
* <code>ValidatorAction</code> message and the <code>Field</code>'s arg
* objects.
*
* @param validator the Validator
* @param request the servlet request
* @param va Validator action
* @param field the validator Field
*/
public static ActionMessage getActionMessage(Validator validator, HttpServletRequest request, ValidatorAction va, Field field) {
Msg msg = field.getMessage(va.getName());
if ((msg != null) && !msg.isResource()) {
return new ActionMessage(msg.getKey(), false);
}
String msgKey = null;
String msgBundle = null;
if (msg == null) {
msgKey = va.getMsg();
} else {
msgKey = msg.getKey();
msgBundle = msg.getBundle();
}
if ((msgKey == null) || (msgKey.length() == 0)) {
return new ActionMessage("??? " + va.getName() + "." + field.getProperty() + " ???", false);
}
ServletContext application = (ServletContext) validator.getParameterValue(SERVLET_CONTEXT_PARAM);
MessageResources messages = getMessageResources(application, request, msgBundle);
Locale locale = RequestUtils.getUserLocale(request, null);
Arg[] args = field.getArgs(va.getName());
String[] argValues = getArgValues(application, request, messages, locale, args);
ActionMessage actionMessage = null;
if (msgBundle == null) {
actionMessage = new ActionMessage(msgKey, argValues);
} else {
String message = messages.getMessage(locale, msgKey, argValues);
actionMessage = new ActionMessage(message, false);
}
return actionMessage;
}
use of org.apache.struts.action.ActionMessage in project sonarqube by SonarSource.
the class ErrorsTag method doStartTag.
// ------------------------------------------------------- Public Methods
/**
* Render the specified error messages if there are any.
*
* @throws JspException if a JSP exception has occurred
*/
public int doStartTag() throws JspException {
// Were any error messages specified?
ActionMessages errors = null;
try {
errors = TagUtils.getInstance().getActionMessages(pageContext, name);
} catch (JspException e) {
TagUtils.getInstance().saveException(pageContext, e);
throw e;
}
if ((errors == null) || errors.isEmpty()) {
return (EVAL_BODY_INCLUDE);
}
boolean headerPresent = TagUtils.getInstance().present(pageContext, bundle, locale, getHeader());
boolean footerPresent = TagUtils.getInstance().present(pageContext, bundle, locale, getFooter());
boolean prefixPresent = TagUtils.getInstance().present(pageContext, bundle, locale, getPrefix());
boolean suffixPresent = TagUtils.getInstance().present(pageContext, bundle, locale, getSuffix());
// Render the error messages appropriately
StringBuffer results = new StringBuffer();
boolean headerDone = false;
String message = null;
Iterator reports = (property == null) ? errors.get() : errors.get(property);
while (reports.hasNext()) {
ActionMessage report = (ActionMessage) reports.next();
if (!headerDone) {
if (headerPresent) {
message = TagUtils.getInstance().message(pageContext, bundle, locale, getHeader());
results.append(message);
}
headerDone = true;
}
if (prefixPresent) {
message = TagUtils.getInstance().message(pageContext, bundle, locale, getPrefix());
results.append(message);
}
if (report.isResource()) {
message = TagUtils.getInstance().message(pageContext, bundle, locale, report.getKey(), report.getValues());
} else {
message = report.getKey();
}
if (message != null) {
results.append(message);
}
if (suffixPresent) {
message = TagUtils.getInstance().message(pageContext, bundle, locale, getSuffix());
results.append(message);
}
}
if (headerDone && footerPresent) {
message = TagUtils.getInstance().message(pageContext, bundle, locale, getFooter());
results.append(message);
}
TagUtils.getInstance().write(pageContext, results.toString());
return (EVAL_BODY_INCLUDE);
}
Aggregations