Author: gvanmatre Date: Sat Feb 24 16:56:08 2007 New Revision: 511385 URL: http://svn.apache.org/viewvc?view=rev&rev=511385 Log: Applied a couple fixed to the Shale CommonsValidator. Both bugs reported by Hasan Turksoy.
* Late bound arguments that are evaluated by the decorated InputRenderer were not being used for server side support. This was an issue for expressions that returned request scoped data such as a message bundle (SHALE-413). * The date validation rule was not functional for server side validation. There was an assumption that a converter-for-class converter was registered for java.util.Data. The code has been change to use the submitted value (String) versus the converted data type passed to validation. This fix will prevent the bogus exception but the date validation rule (server-side) will not have a chance to report a validation message since the converter will always be the first assumed validation rule (SHALE-412). Modified: shale/framework/trunk/shale-validator/src/main/java/org/apache/shale/validator/CommonsValidator.java Modified: shale/framework/trunk/shale-validator/src/main/java/org/apache/shale/validator/CommonsValidator.java URL: http://svn.apache.org/viewvc/shale/framework/trunk/shale-validator/src/main/java/org/apache/shale/validator/CommonsValidator.java?view=diff&rev=511385&r1=511384&r2=511385 ============================================================================== --- shale/framework/trunk/shale-validator/src/main/java/org/apache/shale/validator/CommonsValidator.java (original) +++ shale/framework/trunk/shale-validator/src/main/java/org/apache/shale/validator/CommonsValidator.java Sat Feb 24 16:56:08 2007 @@ -33,6 +33,7 @@ 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; @@ -51,6 +52,7 @@ import org.apache.shale.util.ConverterHelper; import org.apache.shale.util.Messages; import org.apache.shale.util.Tags; +import org.apache.shale.validator.faces.ValidatorInputRenderer; /** * <p>This is a JavaServer Faces <code>Validator</code> that uses @@ -500,7 +502,7 @@ value = localVars.get(templateArgs[i].getKey()); } else if (value != null && value instanceof String) { // if a String, check for a value binding expression - value = tagUtils.eval((String) value); + value = tagUtils.eval((String) value); } target[i] = value; } @@ -787,7 +789,11 @@ ValidatorAction validatorAction = CommonsValidator.getValidatorAction(types[j]); try { - vars.put(SUBMITTED_VALUE_VARNAME, value); + if (component instanceof EditableValueHolder) { + vars.put(SUBMITTED_VALUE_VARNAME, ((EditableValueHolder) component).getSubmittedValue()); + } else { + vars.put(SUBMITTED_VALUE_VARNAME, value); + } Class validatorClass = loadValidatorClass(validatorAction); Class[] paramClasses = this.loadMethodParamClasses(validatorAction); Object[] paramValues = this.loadMethodParamValues(context, validatorAction, paramClasses); @@ -797,10 +803,24 @@ validator = validatorClass.newInstance(); } Boolean r = (Boolean) validatorMethod.invoke(validator, paramValues); + + Map localVars = null; + // A map that captures information about a component that might contain state for commons + // validators properties. The map is organized by a hierarchy "clientId/validatorType/vars". + // It is captured at render time. + Map ids = (Map) component.getAttributes().get(ValidatorInputRenderer.VALIDATOR_CLIENTIDS_ATTR); + if (ids != null) { + String clientId = component.getClientId(context); + Map validatorVars = (Map) ids.get(clientId); + if (validatorVars != null) { + localVars = (Map) validatorVars.get(getType()); + } + } + if (r.equals(Boolean.FALSE)) { throw new ValidatorException(new FacesMessage( FacesMessage.SEVERITY_ERROR, - getErrorMessage(context, validatorAction, null), null)); + getErrorMessage(context, validatorAction, localVars), null)); } } catch (IllegalArgumentException e) { throw new RuntimeException(messages.getMessage("commonsValidator.intException",