import javax.servlet.http.HttpServletRequest; import org.apache.commons.validator.Field; import org.apache.commons.validator.GenericTypeValidator; import org.apache.commons.validator.GenericValidator; (Web hosting service)

import javax.servlet.http.HttpServletRequest; import org.apache.commons.validator.Field; import org.apache.commons.validator.GenericTypeValidator; import org.apache.commons.validator.GenericValidator; import org.apache.commons.validator.ValidatorAction; import org.apache.commons.validator.ValidatorUtil; import org.apache.struts.action.ActionErrors; import org.apache.struts.util.StrutsValidatorUtil; public class NewValidator implements Serializable { /** * A validate routine that ensures the value is either true or false. */ public static boolean validateBoolean( Object bean, ValidatorAction va, Field field, ActionErrors errors, HttpServletRequestrequest ) { String value = null; // The boolean value is stored as a String if (field.getProperty() != null && field.getProperty().length( ) > 0){ value = ValidatorUtil.getValueAsString(bean, field.getProperty( ) ); } Boolean result = Boolean.valueOf(value); if ( result == null ){ errors.add( field.getKey( ), StrutsValidatorUtil.getActionError(request, va, field)); } // Return true if the value was successfully converted, false otherwise return (errors.empty( )); } } The next step is to add this new rule to the validation-rules.xml file, or to a new file to keep your customized rules separate. The validator element for the validateBooleanrule should look something like: Visit our web design programs services for an affordable and reliable webhost to suit all your needs.

Leave a Reply