Author: alexsmirnov
Date: 2008-07-23 17:35:42 -0400 (Wed, 23 Jul 2008)
New Revision: 9759
Modified:
trunk/ui/beanValidator/src/main/java/org/richfaces/validator/BeanValidator.java
Log:
https://jira.jboss.org/jira/browse/RF-3992
Modified: trunk/ui/beanValidator/src/main/java/org/richfaces/validator/BeanValidator.java
===================================================================
---
trunk/ui/beanValidator/src/main/java/org/richfaces/validator/BeanValidator.java 2008-07-23
16:52:48 UTC (rev 9758)
+++
trunk/ui/beanValidator/src/main/java/org/richfaces/validator/BeanValidator.java 2008-07-23
21:35:42 UTC (rev 9759)
@@ -104,25 +104,30 @@
public String[] validate(FacesContext context, ValueExpression target,
Object value) {
// TODO - check null parameters.
- checkInputParameters(context, target, value);
- ELContext elContext = context.getELContext();
- ValidationResolver validationResolver = new ValidationResolver(
- elContext.getELResolver());
- ELContextWrapper wrappedElContext = new ELContextWrapper(elContext,
- validationResolver);
- Locale locale = calculateLocale(context);
- wrappedElContext.setLocale(locale);
- // TODO - handle ELExceptions ?
- try {
- target.setValue(wrappedElContext, value);
- } catch (ELException e) {
- throw new FacesException(e);
+ if (null == context) {
+ throw new FacesException(INPUT_PARAMETERS_IS_NOT_CORRECT);
}
- if (validationResolver.isValid()) {
- return null;
- } else {
- return validationResolver.getValidationMessages();
+ String[] validationMessages = null;
+ if (null != target) {
+ ELContext elContext = context.getELContext();
+ ValidationResolver validationResolver = new ValidationResolver(
+ elContext.getELResolver());
+ ELContextWrapper wrappedElContext = new ELContextWrapper(elContext,
+ validationResolver);
+ Locale locale = calculateLocale(context);
+ wrappedElContext.setLocale(locale);
+ // TODO - handle ELExceptions ?
+ try {
+ target.setValue(wrappedElContext, value);
+ } catch (ELException e) {
+ throw new FacesException(e);
+ }
+ if (!validationResolver.isValid()) {
+ validationMessages = validationResolver.getValidationMessages();
+ }
+
}
+ return validationMessages;
}
protected Locale calculateLocale(FacesContext context) {
@@ -137,8 +142,8 @@
// Method for checking input parameters for prevent NPE
private void checkInputParameters(FacesContext context,
- ValueExpression target, Object value) {
- if (null == context || null == target || null == value) {
+ ValueExpression target) {
+ if (null == context || null == target ) {
throw new FacesException(INPUT_PARAMETERS_IS_NOT_CORRECT);
}
}
@@ -172,19 +177,27 @@
}
@SuppressWarnings("unchecked")
- public String[] validateGraph(FacesContext context, Object value, Set<String>
profiles) {
+ public String[] validateGraph(FacesContext context, Object value,
+ Set<String> profiles) {
+ if (null == context) {
+ throw new FacesException(INPUT_PARAMETERS_IS_NOT_CORRECT);
+ }
String validationMessages[] = null;
- ClassValidator<Object> validator = (ClassValidator<Object>)
getValidator(value
- .getClass(), calculateLocale(context));
- if (validator.hasValidationRules()) {
- InvalidValue[] invalidValues = validator.getInvalidValues(value);
- if(null != invalidValues && invalidValues.length >0){
- validationMessages = new String[invalidValues.length];
- for (int i = 0; i < invalidValues.length; i++) {
- InvalidValue invalidValue = invalidValues[i];
- validationMessages[i] = invalidValue.getMessage();
+ if (null != value) {
+ ClassValidator<Object> validator = (ClassValidator<Object>) getValidator(
+ value.getClass(), calculateLocale(context));
+ if (validator.hasValidationRules()) {
+ InvalidValue[] invalidValues = validator
+ .getInvalidValues(value);
+ if (null != invalidValues && invalidValues.length > 0) {
+ validationMessages = new String[invalidValues.length];
+ for (int i = 0; i < invalidValues.length; i++) {
+ InvalidValue invalidValue = invalidValues[i];
+ validationMessages[i] = invalidValue.getMessage();
+ }
}
}
+
}
return validationMessages;
}