• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Paul Clapham
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Roland Mueller
  • Piet Souris
Bartenders:

Having problem with struts validator for error message

 
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can anyone help, the below code gets executed properly in my debug mode, however it does show the error message to the screen. It works fine for all other errors except this validator plugin. Could anyone tell me what's wrong with my code below:

validation-rule.xml:

<validator name="dateRange"
classname="ca.cn.ems.web.forms.DateRangeValidator"
method="validateTwoDate"
methodParams="java.lang.Object,
org.apache.commons.validator.ValidatorAction,
org.apache.commons.validator.Field,
org.apache.struts.action.ActionErrors,
javax.servlet.http.HttpServletRequest,
javax.servlet.ServletContext"
depends=""
msg="error.invalid.daterange"/>

validation.xml:

<form-validation>
<formset>
<form name="equipmentForm">
<field property="beginDate" depends="required,date">
<arg key="form.beginDate" />
<var>
<var-name>datePatternStrict</var-name>
<var-value>yyyy-MM-dd</var-value>
</var>
</field>
<field property="endDate" depends="required,date,dateRange">
<arg key="form.endDate" />
<var>
<var-name>datePatternStrict</var-name>
<var-value>yyyy-MM-dd</var-value>
</var>
</field>
</form>
</formset>
</form-validation>

Java:


public static boolean validateTwoDate(java.lang.Object bean,
ValidatorAction va,
Field field,
ActionErrors errors,
HttpServletRequest request,
ServletContext application) {

if (LOGGER.isInfoEnabled()) {
LOGGER.info("enter DateRangeValidator.validateTwoDate");
}

String endDate = ValidatorUtils.getValueAsString(bean, field
.getProperty());

String beginDate = ValidatorUtils.getValueAsString(bean, "beginDate");

Date startDateRet = CommonUtil.getDate(beginDate);
Date endDateRet = CommonUtil.getDate(endDate);

if (!GenericValidator.isBlankOrNull(endDate)) {
try {
if (endDateRet.before(startDateRet)) {
errors.add(field.getKey(),
Resources.getActionError(request, va, field));

return false;
}
} catch (Exception e) {
errors.add(field.getKey(),
Resources.getActionError(request, va, field));

return false;
}

}
return true;
}


Conclusion I think that the problem seems to be the java code, could anyone tell me what I'm doing wrong :

errors.add(field.getKey(), Resources.getActionError(request, va, field));

return false;
 
reply
    Bookmark Topic Watch Topic
  • New Topic