In struts-config.xml
<form-bean name="myForm" type="com.validator.CustomeDynaValidatorForm">
<form-property name="testId" type="java.lang.Long"/>
</form-bean>
In validation.xml
<form name="myForm">
<field property="testId" depends="required">
<msg name="required" key="test ID required."/>
</field>
</form>
In validation-rules.xml
<validator name="required"
classname="com.validator.CustomFieldChecks"
method="validateRequired"
methodParams="java.lang.Object,
org.apache.commons.validator.ValidatorAction,
org.apache.commons.validator.Field,
org.apache.struts.action.ActionMessages,
org.apache.commons.validator.Validator,
javax.servlet.http.HttpServletRequest"
msg=""/>
In CustomFieldChecks.java
public static boolean validateRequired(Object bean, ValidatorAction va, Field field, ActionMessages errors,
Validator validator, HttpServletRequest request)
{
String value = null;
if (isString(bean))
{
value = (String) bean;
}
else
{
value = ValidatorUtils.getValueAsString(bean,
field.getProperty());
**// here value is 0 , when the field is left blank in UI**
}
if (GenericValidator.isBlankOrNull(value))
{
//add error message
return false;
}
else
{
return true;
}
}
Can someone plz let me know , how do i make sure that if the field is left blank in UI , the value should be null not 0 . Is there a way to do so??? I am using struts 1.2