Author: mrdon
Date: Fri Sep 9 12:58:25 2005
New Revision: 279861
URL: http://svn.apache.org/viewcvs?rev=279861&view=rev
Log:
Adding numeric validations that use the current locale:
* byteLocale
* shortLocale
* integerLocale
* longLocale
* floatLocale
* doubleLocale
PR: 21282
Modified:
struts/core/trunk/conf/java/validator-rules.xml
struts/core/trunk/src/java/org/apache/struts/validator/FieldChecks.java
Modified: struts/core/trunk/conf/java/validator-rules.xml
URL:
http://svn.apache.org/viewcvs/struts/core/trunk/conf/java/validator-rules.xml?rev=279861&r1=279860&r2=279861&view=diff
==============================================================================
--- struts/core/trunk/conf/java/validator-rules.xml (original)
+++ struts/core/trunk/conf/java/validator-rules.xml Fri Sep 9 12:58:25 2005
@@ -207,6 +207,84 @@
msg="errors.double"/>
+ <validator name="byteLocale"
+ classname="org.apache.struts.validator.FieldChecks"
+ method="validateByteLocale"
+ 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"
+ depends=""
+ msg="errors.byte"/>
+
+
+ <validator name="shortLocale"
+ classname="org.apache.struts.validator.FieldChecks"
+ method="validateShortLocale"
+ 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"
+ depends=""
+ msg="errors.short"/>
+
+
+ <validator name="integerLocale"
+ classname="org.apache.struts.validator.FieldChecks"
+ method="validateIntegerLocale"
+ 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"
+ depends=""
+ msg="errors.integer"/>
+
+
+
+ <validator name="longLocale"
+ classname="org.apache.struts.validator.FieldChecks"
+ method="validateLongLocale"
+ 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"
+ depends=""
+ msg="errors.long"/>
+
+
+ <validator name="floatLocale"
+ classname="org.apache.struts.validator.FieldChecks"
+ method="validateFloatLocale"
+ 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"
+ depends=""
+ msg="errors.float"/>
+
+ <validator name="doubleLocale"
+ classname="org.apache.struts.validator.FieldChecks"
+ method="validateDoubleLocale"
+ 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"
+ depends=""
+ msg="errors.double"/>
+
+
<validator name="date"
classname="org.apache.struts.validator.FieldChecks"
method="validateDate"
Modified:
struts/core/trunk/src/java/org/apache/struts/validator/FieldChecks.java
URL:
http://svn.apache.org/viewcvs/struts/core/trunk/src/java/org/apache/struts/validator/FieldChecks.java?rev=279861&r1=279860&r2=279861&view=diff
==============================================================================
--- struts/core/trunk/src/java/org/apache/struts/validator/FieldChecks.java
(original)
+++ struts/core/trunk/src/java/org/apache/struts/validator/FieldChecks.java Fri
Sep 9 12:58:25 2005
@@ -276,6 +276,45 @@
return result == null ? Boolean.FALSE : result;
}
+
+
+ /**
+ * Checks if the field can safely be converted to a byte primitive.
+ *
+ [EMAIL PROTECTED] bean The bean validation is being performed on.
+ [EMAIL PROTECTED] va The <code>ValidatorAction</code> that is currently
being performed.
+ [EMAIL PROTECTED] field The <code>Field</code> object associated with the
current
+ *field being validated.
+ [EMAIL PROTECTED] errors The <code>ActionMessages</code> object to add
errors to if
+ *any validation errors occur.
+ * @param validator The <code>Validator</code> instance, used to access
+ * other field values.
+ [EMAIL PROTECTED] request Current request object.
+ [EMAIL PROTECTED] true if valid, false otherwise.
+ */
+ public static Object validateByteLocale(Object bean,
+ ValidatorAction va, Field field,
+ ActionMessages errors,
+ Validator validator,
+ HttpServletRequest request) {
+
+ Object result = null;
+ String value = null;
+ value = evaluateBean(bean, field);
+
+ if (GenericValidator.isBlankOrNull(value)) {
+ return Boolean.TRUE;
+ }
+
+ Locale locale = RequestUtils.getUserLocale(request, null);
+ result = GenericTypeValidator.formatByte(value, locale);
+
+ if (result == null) {
+ errors.add(field.getKey(), Resources.getActionMessage(validator,
request, va, field));
+ }
+
+ return result == null ? Boolean.FALSE : result;
+ }
/**
* @param bean
@@ -328,6 +367,44 @@
return result == null ? Boolean.FALSE : result;
}
+
+
+ /**
+ * Checks if the field can safely be converted to a short primitive.
+ *
+ * @param bean The bean validation is being performed on.
+ * @param va The <code>ValidatorAction</code> that is currently being
performed.
+ * @param field The <code>Field</code> object associated with the current
+ * field being validated.
+ * @param errors The <code>ActionMessages</code> object to add errors to if
+ * any validation errors occur.
+ * @param validator The <code>Validator</code> instance, used to access
+ * other field values.
+ * @param request Current request object.
+ * @return true if valid, false otherwise.
+ */
+ public static Object validateShortLocale(Object bean,
+ ValidatorAction va, Field field,
+ ActionMessages errors,
+ Validator validator,
+ HttpServletRequest request) {
+ Object result = null;
+ String value = null;
+ value = evaluateBean(bean, field);
+
+ if (GenericValidator.isBlankOrNull(value)) {
+ return Boolean.TRUE;
+ }
+
+ Locale locale = RequestUtils.getUserLocale(request, null);
+ result = GenericTypeValidator.formatShort(value, locale);
+
+ if (result == null) {
+ errors.add(field.getKey(), Resources.getActionMessage(validator,
request, va, field));
+ }
+
+ return result == null ? Boolean.FALSE : result;
+ }
/**
@@ -366,6 +443,44 @@
return result == null ? Boolean.FALSE : result;
}
+
+ /**
+ * Checks if the field can safely be converted to an int primitive.
+ *
+ * @param bean The bean validation is being performed on.
+ * @param va The <code>ValidatorAction</code> that is currently
being performed.
+ * @param field The <code>Field</code> object associated with the
current
+ * field being validated.
+ * @param errors The <code>ActionMessages</code> object to add errors
to if any
+ * validation errors occur.
+ * @param validator The <code>Validator</code> instance, used to access
+ * other field values.
+ * @param request Current request object.
+ * @return true if valid, false otherwise.
+ */
+ public static Object validateIntegerLocale(Object bean,
+ ValidatorAction va, Field field,
+ ActionMessages errors,
+ Validator validator,
+ HttpServletRequest request) {
+ Object result = null;
+ String value = null;
+ value = evaluateBean(bean, field);
+
+ if (GenericValidator.isBlankOrNull(value)) {
+ return Boolean.TRUE;
+ }
+
+ Locale locale = RequestUtils.getUserLocale(request, null);
+ result = GenericTypeValidator.formatInt(value, locale);
+
+ if (result == null) {
+ errors.add(field.getKey(), Resources.getActionMessage(validator,
request, va, field));
+ }
+
+ return result == null ? Boolean.FALSE : result;
+ }
+
/**
* Checks if the field can safely be converted to a long primitive.
@@ -402,6 +517,44 @@
return result == null ? Boolean.FALSE : result;
}
+
+
+ /**
+ * Checks if the field can safely be converted to a long primitive.
+ *
+ * @param bean The bean validation is being performed on.
+ * @param va The <code>ValidatorAction</code> that is currently
being performed.
+ * @param field The <code>Field</code> object associated with the
current
+ * field being validated.
+ * @param errors The <code>ActionMessages</code> object to add errors
to if any
+ * validation errors occur.
+ * @param validator The <code>Validator</code> instance, used to access
+ * other field values.
+ * @param request Current request object.
+ * @return true if valid, false otherwise.
+ */
+ public static Object validateLongLocale(Object bean,
+ ValidatorAction va, Field field,
+ ActionMessages errors,
+ Validator validator,
+ HttpServletRequest request) {
+ Object result = null;
+ String value = null;
+ value = evaluateBean(bean, field);
+
+ if (GenericValidator.isBlankOrNull(value)) {
+ return Boolean.TRUE;
+ }
+
+ Locale locale = RequestUtils.getUserLocale(request, null);
+ result = GenericTypeValidator.formatLong(value, locale);
+
+ if (result == null) {
+ errors.add(field.getKey(), Resources.getActionMessage(validator,
request, va, field));
+ }
+
+ return result == null ? Boolean.FALSE : result;
+ }
/**
@@ -440,6 +593,44 @@
return result == null ? Boolean.FALSE : result;
}
+
+ /**
+ * Checks if the field can safely be converted to a float primitive.
+ *
+ * @param bean The bean validation is being performed on.
+ * @param va The <code>ValidatorAction</code> that is currently
being performed.
+ * @param field The <code>Field</code> object associated with the
current
+ * field being validated.
+ * @param errors The <code>ActionMessages</code> object to add errors
to if any
+ * validation errors occur.
+ * @param validator The <code>Validator</code> instance, used to access
+ * other field values.
+ * @param request Current request object.
+ * @return true if valid, false otherwise.
+ */
+ public static Object validateFloatLocale(Object bean,
+ ValidatorAction va, Field field,
+ ActionMessages errors,
+ Validator validator,
+ HttpServletRequest request) {
+ Object result = null;
+ String value = null;
+ value = evaluateBean(bean, field);
+
+ if (GenericValidator.isBlankOrNull(value)) {
+ return Boolean.TRUE;
+ }
+
+ Locale locale = RequestUtils.getUserLocale(request, null);
+ result = GenericTypeValidator.formatFloat(value, locale);
+
+ if (result == null) {
+ errors.add(field.getKey(), Resources.getActionMessage(validator,
request, va, field));
+ }
+
+ return result == null ? Boolean.FALSE : result;
+ }
+
/**
* Checks if the field can safely be converted to a double primitive.
@@ -469,6 +660,44 @@
}
result = GenericTypeValidator.formatDouble(value);
+
+ if (result == null) {
+ errors.add(field.getKey(), Resources.getActionMessage(validator,
request, va, field));
+ }
+
+ return result == null ? Boolean.FALSE : result;
+ }
+
+
+ /**
+ * Checks if the field can safely be converted to a double primitive.
+ *
+ * @param bean The bean validation is being performed on.
+ * @param va The <code>ValidatorAction</code> that is currently
being performed.
+ * @param field The <code>Field</code> object associated with the
current
+ * field being validated.
+ * @param errors The <code>ActionMessages</code> object to add errors
to if any
+ * validation errors occur.
+ * @param validator The <code>Validator</code> instance, used to access
+ * other field values.
+ * @param request Current request object.
+ * @return true if valid, false otherwise.
+ */
+ public static Object validateDoubleLocale(Object bean,
+ ValidatorAction va, Field field,
+ ActionMessages errors,
+ Validator validator,
+ HttpServletRequest request) {
+ Object result = null;
+ String value = null;
+ value = evaluateBean(bean, field);
+
+ if (GenericValidator.isBlankOrNull(value)) {
+ return Boolean.TRUE;
+ }
+
+ Locale locale = RequestUtils.getUserLocale(request, null);
+ result = GenericTypeValidator.formatDouble(value, locale);
if (result == null) {
errors.add(field.getKey(), Resources.getActionMessage(validator,
request, va, field));
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]