package validate;
import java.io.Serializable;
import javax.servlet.http.HttpServletRequest;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.commons.validator.Field;
import org.apache.commons.validator.ValidatorAction;
import org.apache.commons.validator.util.ValidatorUtils;
import org.apache.struts.action.ActionMessages;
import org.apache.struts.action.ActionMessage;
import org.apache.struts.util.RequestUtils;
import org.apache.struts.validator.Resources;
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,
ActionMessages errors,
HttpServletRequest request) {
String value = null;
// The boolean value is stored as a String
if (field.getProperty() != null && field.getProperty().length( ) > 0){
value = ValidatorUtils.getValueAsString(bean, field.getProperty( ) );
}
if ( value==null || !(value.equalsIgnoreCase("true")||value.equalsIgnoreCase("false"))){
errors.add( field.getKey( ),
Resources.getActionMessage(request, va, field));
}
// Return true if the value was successfully converted, false otherwise
return (errors.isEmpty( ));
}
}