You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@struts.apache.org by dg...@apache.org on 2005/05/30 14:24:15 UTC
svn commit: r179051 -
/struts/shale/trunk/core-library/src/java/org/apache/shale/validator/CommonsValidator.java
Author: dgeary
Date: Mon May 30 05:24:14 2005
New Revision: 179051
URL: http://svn.apache.org/viewcvs?rev=179051&view=rev
Log:
Added Manfred Klug's patch that uses a component's submitted value for validation instead of the converted value
Modified:
struts/shale/trunk/core-library/src/java/org/apache/shale/validator/CommonsValidator.java
Modified: struts/shale/trunk/core-library/src/java/org/apache/shale/validator/CommonsValidator.java
URL: http://svn.apache.org/viewcvs/struts/shale/trunk/core-library/src/java/org/apache/shale/validator/CommonsValidator.java?rev=179051&r1=179050&r2=179051&view=diff
==============================================================================
--- struts/shale/trunk/core-library/src/java/org/apache/shale/validator/CommonsValidator.java (original)
+++ struts/shale/trunk/core-library/src/java/org/apache/shale/validator/CommonsValidator.java Mon May 30 05:24:14 2005
@@ -34,6 +34,7 @@
import java.util.logging.Logger;
import javax.faces.application.Application;
import javax.faces.application.FacesMessage;
+import javax.faces.component.EditableValueHolder;
import javax.faces.component.UIComponent;
import javax.faces.context.ExternalContext;
import javax.faces.context.FacesContext;
@@ -407,18 +408,23 @@
Object[] p = getParams();
Object[] params = new Object[p.length + 1];
- params[0] = convert(value, paramTypes[0]);
+ params[0] = convert(value, paramTypes[0], component);
for (int i = 1; i < params.length; i++)
- params[i] = convert(p[i - 1], paramTypes[i]);
+ params[i] = convert(p[i - 1], paramTypes[i], null);
try {
Boolean r = (Boolean) validatorMethod.invoke(validator, params);
if (r.equals(Boolean.FALSE)) {
- FacesMessage message = new FacesMessage(
- FacesMessage.SEVERITY_ERROR,
- getErrorMessage(value, context), null);
- throw new ValidatorException(message);
+ Object errorValue = value;
+
+ if(component instanceof EditableValueHolder)
+ errorValue = ((EditableValueHolder)component)
+ .getSubmittedValue();
+
+ throw new ValidatorException(new FacesMessage(
+ FacesMessage.SEVERITY_ERROR,
+ getErrorMessage(errorValue, context), null));
}
} catch (IllegalAccessException ex) {
logger.log(Level.SEVERE, "can't invoke validator", ex);
@@ -509,17 +515,25 @@
// ----------------------------------------------------- Static Initialization
-
/**
* <p>A utility method that converts an object to an instance
* of a given class, such as converting <code>"true"</code>
* for example, into <code>Boolean.TRUE</code>.
+ * <p>If the component passed to this method is an instance of
+ * <code>EditableValueHolder</code> and the object's class is
+ * <code>String</code>, this method returns the component's
+ * submitted value, without converting it to a string. The
+ * <code>component</code> parameter can be <code>null</code>.
*
* @param obj The object to convert
* @param cl The type of object to convert to
+ * @param component The component whose value we are converting
*/
- private static Object convert(Object obj, Class cl) {
+ private static Object convert(Object obj, Class cl, UIComponent component) {
if (cl.isInstance(obj)) return obj;
+ if (cl == String.class && component != null &&
+ component instanceof EditableValueHolder)
+ return ((EditableValueHolder)component).getSubmittedValue();
if (cl == String.class) return "" + obj;
if (obj instanceof String) {
String str = (String) obj;
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@struts.apache.org
For additional commands, e-mail: dev-help@struts.apache.org