File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Struts and the fly likes Having problem with struts validator for error message Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Having problem with struts validator for error message" Watch "Having problem with struts validator for error message" New topic
Author

Having problem with struts validator for error message

bobby, morkos
Ranch Hand

Joined: Jan 04, 2002
Posts: 82
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;
 
 
subject: Having problem with struts validator for error message