This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Having problem with struts validator for error message

 
bobby, morkos
Ranch Hand
Posts: 82
  • 0
  • Mark post as helpful
  • send pies
  • 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;
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic