Author: alexsmirnov
Date: 2011-03-07 15:14:44 -0500 (Mon, 07 Mar 2011)
New Revision: 22077
Added:
trunk/ui/validator/ui/src/main/java/org/richfaces/component/behavior/MessageUpdateScript.java
trunk/ui/validator/ui/src/main/java/org/richfaces/view/facelets/html/GraphValidatorHandler.java
Removed:
trunk/ui/validator/ui/src/main/java/org/richfaces/validator/ClonedObjectResolver.java
Modified:
trunk/ui/validator/
trunk/ui/validator/api/src/main/java/org/richfaces/el/ValueDescriptor.java
trunk/ui/validator/api/src/main/java/org/richfaces/el/ValueExpressionAnalayser.java
trunk/ui/validator/api/src/main/java/org/richfaces/javascript/ScriptNotFoundException.java
trunk/ui/validator/api/src/main/java/org/richfaces/validator/FacesConverterService.java
trunk/ui/validator/api/src/main/java/org/richfaces/validator/FacesValidatorService.java
trunk/ui/validator/api/src/main/java/org/richfaces/validator/GraphValidatorState.java
trunk/ui/validator/ui/src/main/java/org/richfaces/component/AbstractGraphValidator.java
trunk/ui/validator/ui/src/main/java/org/richfaces/component/behavior/ClientValidatorImpl.java
trunk/ui/validator/ui/src/main/java/org/richfaces/el/CapturingELContext.java
trunk/ui/validator/ui/src/main/java/org/richfaces/el/ValueExpressionAnalayserImpl.java
trunk/ui/validator/ui/src/main/java/org/richfaces/javascript/ClientScriptServiceImpl.java
trunk/ui/validator/ui/src/main/java/org/richfaces/renderkit/html/AjaxOnlyScript.java
trunk/ui/validator/ui/src/main/java/org/richfaces/renderkit/html/ClientAndAjaxScript.java
trunk/ui/validator/ui/src/main/java/org/richfaces/renderkit/html/ClientOnlyScript.java
trunk/ui/validator/ui/src/main/java/org/richfaces/validator/BeanValidatorServiceImpl.java
trunk/ui/validator/ui/src/main/java/org/richfaces/validator/ConverterServiceImpl.java
trunk/ui/validator/ui/src/main/java/org/richfaces/validator/FacesBeanValidator.java
trunk/ui/validator/ui/src/main/java/org/richfaces/validator/FacesServiceBase.java
trunk/ui/validator/ui/src/main/java/org/richfaces/validator/FacesValidatorServiceImpl.java
trunk/ui/validator/ui/src/main/resources/META-INF/csv.xml
trunk/ui/validator/ui/src/main/resources/META-INF/resources/org.richfaces/richfaces-csv.js
trunk/ui/validator/ui/src/test/java/org/richfaces/component/behavior/BehaviorGetConverterTest.java
trunk/ui/validator/ui/src/test/java/org/richfaces/component/behavior/BehaviorGetValidatorTest.java
trunk/ui/validator/ui/src/test/java/org/richfaces/el/ELTestBase.java
trunk/ui/validator/ui/src/test/java/org/richfaces/el/TestCaptureEL.java
trunk/ui/validator/ui/src/test/java/org/richfaces/el/ValueExpressionAnalayserTest.java
trunk/ui/validator/ui/src/test/java/org/richfaces/javascript/client/MockTestBase.java
trunk/ui/validator/ui/src/test/java/org/richfaces/javascript/client/converter/BooleanConverterTest.java
trunk/ui/validator/ui/src/test/java/org/richfaces/javascript/client/converter/ByteConverterTest.java
trunk/ui/validator/ui/src/test/java/org/richfaces/javascript/client/converter/ConverterTestBase.java
trunk/ui/validator/ui/src/test/java/org/richfaces/javascript/client/converter/NumberConverterTest.java
trunk/ui/validator/ui/src/test/java/org/richfaces/javascript/client/converter/ShortConverterTest.java
trunk/ui/validator/ui/src/test/java/org/richfaces/javascript/client/validator/DoubleRangeValidatorTest.java
trunk/ui/validator/ui/src/test/java/org/richfaces/javascript/client/validator/LengthValidatorTest.java
trunk/ui/validator/ui/src/test/java/org/richfaces/javascript/client/validator/LongRangeValidatorTest.java
trunk/ui/validator/ui/src/test/java/org/richfaces/javascript/client/validator/MaxValidatorTest.java
trunk/ui/validator/ui/src/test/java/org/richfaces/javascript/client/validator/ValidatorTestBase.java
trunk/ui/validator/ui/src/test/java/org/richfaces/validator/FacesConverterServiceTest.java
trunk/ui/validator/ui/src/test/java/org/richfaces/validator/FacesValidatorServiceTest.java
Log:
Merge changes from 4.0.x
Property changes on: trunk/ui/validator
___________________________________________________________________
Added: svn:mergeinfo
+ /branches/4.0.X/ui/validator:21810-22076
Modified: trunk/ui/validator/api/src/main/java/org/richfaces/el/ValueDescriptor.java
===================================================================
--- trunk/ui/validator/api/src/main/java/org/richfaces/el/ValueDescriptor.java 2011-03-07
17:31:10 UTC (rev 22076)
+++ trunk/ui/validator/api/src/main/java/org/richfaces/el/ValueDescriptor.java 2011-03-07
20:14:44 UTC (rev 22077)
@@ -14,24 +14,17 @@
private final Class<?> beanType;
- private final Class<?> propertyType;
-
/**
* @param beanType
* @param name
* @param propertyType
* @param readOnly
*/
- public ValueDescriptor(Class<?> beanType, String name, Class<?>
propertyType) {
+ public ValueDescriptor(Class<?> beanType, String name) {
this.beanType = beanType;
this.name = name;
- this.propertyType = propertyType;
}
- public ValueDescriptor(Class<?> beanType, String name) {
- this(beanType,name,Object.class);
- }
-
/**
* @return the name
*/
@@ -47,13 +40,6 @@
return beanType;
}
- /**
- * @return the propertyType
- */
- public Class<?> getPropertyType() {
- return propertyType;
- }
-
/* (non-Javadoc)
* @see java.lang.Object#hashCode()
*/
Modified:
trunk/ui/validator/api/src/main/java/org/richfaces/el/ValueExpressionAnalayser.java
===================================================================
---
trunk/ui/validator/api/src/main/java/org/richfaces/el/ValueExpressionAnalayser.java 2011-03-07
17:31:10 UTC (rev 22076)
+++
trunk/ui/validator/api/src/main/java/org/richfaces/el/ValueExpressionAnalayser.java 2011-03-07
20:14:44 UTC (rev 22077)
@@ -3,6 +3,7 @@
*/
package org.richfaces.el;
+import javax.el.ELException;
import javax.el.ValueExpression;
import javax.faces.context.FacesContext;
@@ -13,6 +14,8 @@
*/
public interface ValueExpressionAnalayser {
- ValueDescriptor getPropertyDescriptor(FacesContext context, ValueExpression
expression);
+ ValueDescriptor getPropertyDescriptor(FacesContext context, ValueExpression
expression) throws ELException;
+ ValueDescriptor updateValueAndGetPropertyDescriptor(FacesContext context,
ValueExpression expression, Object newValue) throws ELException;
+
}
Modified:
trunk/ui/validator/api/src/main/java/org/richfaces/javascript/ScriptNotFoundException.java
===================================================================
---
trunk/ui/validator/api/src/main/java/org/richfaces/javascript/ScriptNotFoundException.java 2011-03-07
17:31:10 UTC (rev 22076)
+++
trunk/ui/validator/api/src/main/java/org/richfaces/javascript/ScriptNotFoundException.java 2011-03-07
20:14:44 UTC (rev 22077)
@@ -3,22 +3,19 @@
public class ScriptNotFoundException extends Exception {
public ScriptNotFoundException() {
- // TODO Auto-generated constructor stub
+ super();
}
public ScriptNotFoundException(String message) {
super(message);
- // TODO Auto-generated constructor stub
}
public ScriptNotFoundException(Throwable cause) {
super(cause);
- // TODO Auto-generated constructor stub
}
public ScriptNotFoundException(String message, Throwable cause) {
super(message, cause);
- // TODO Auto-generated constructor stub
}
}
Modified:
trunk/ui/validator/api/src/main/java/org/richfaces/validator/FacesConverterService.java
===================================================================
---
trunk/ui/validator/api/src/main/java/org/richfaces/validator/FacesConverterService.java 2011-03-07
17:31:10 UTC (rev 22076)
+++
trunk/ui/validator/api/src/main/java/org/richfaces/validator/FacesConverterService.java 2011-03-07
20:14:44 UTC (rev 22077)
@@ -1,5 +1,6 @@
package org.richfaces.validator;
+import javax.faces.component.EditableValueHolder;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;
@@ -11,6 +12,6 @@
*/
public interface FacesConverterService {
- ConverterDescriptor getConverterDescription(FacesContext context,Converter
converter);
+ ConverterDescriptor getConverterDescription(FacesContext context,EditableValueHolder
input, Converter converter);
}
Modified:
trunk/ui/validator/api/src/main/java/org/richfaces/validator/FacesValidatorService.java
===================================================================
---
trunk/ui/validator/api/src/main/java/org/richfaces/validator/FacesValidatorService.java 2011-03-07
17:31:10 UTC (rev 22076)
+++
trunk/ui/validator/api/src/main/java/org/richfaces/validator/FacesValidatorService.java 2011-03-07
20:14:44 UTC (rev 22077)
@@ -1,10 +1,11 @@
package org.richfaces.validator;
+import javax.faces.component.EditableValueHolder;
import javax.faces.context.FacesContext;
import javax.faces.validator.Validator;
public interface FacesValidatorService {
- ValidatorDescriptor getValidatorDescription(FacesContext context,Validator
validator);
+ ValidatorDescriptor getValidatorDescription(FacesContext context,EditableValueHolder
component, Validator validator);
}
Modified:
trunk/ui/validator/api/src/main/java/org/richfaces/validator/GraphValidatorState.java
===================================================================
---
trunk/ui/validator/api/src/main/java/org/richfaces/validator/GraphValidatorState.java 2011-03-07
17:31:10 UTC (rev 22076)
+++
trunk/ui/validator/api/src/main/java/org/richfaces/validator/GraphValidatorState.java 2011-03-07
20:14:44 UTC (rev 22077)
@@ -1,12 +1,21 @@
package org.richfaces.validator;
+import java.util.IdentityHashMap;
+import java.util.Map;
+import javax.faces.context.FacesContext;
+
+
public final class GraphValidatorState {
- public static final String STATE_ATTRIBUTE_PREFIX =
"org.richfaces.GraphValidator:";
- boolean active = false;
- Object cloned;
- Object base;
- Object property;
+ public static final String STATE_ATTRIBUTE =
"org.richfaces.GraphValidator:";
+ private boolean active = false;
+ private final Object cloned;
+
+
+ public GraphValidatorState(Object cloned) {
+ this.cloned = cloned;
+ }
+
/**
* @return the active
*/
@@ -29,57 +38,28 @@
return cloned;
}
- /**
- * @param cloned
- * the cloned to set
- */
- public void setCloned(Object cloned) {
- this.cloned = cloned;
+ public static Object getActiveClone(FacesContext context,Object base){
+ GraphValidatorState state = getState(context, base);
+ if(null == state || !state.isActive()){
+ return null;
+ }
+ return state.getCloned();
}
- /**
- * @return the base
- */
- public Object getBase() {
- return base;
+ public static GraphValidatorState getState(FacesContext context,Object base){
+ return getStateMap(context).get(base);
}
- /**
- * @param base
- * the base to set
- */
- public void setBase(Object base) {
- this.base = base;
+ public static void setState(FacesContext context,Object base,GraphValidatorState
state){
+ getStateMap(context).put(base, state);
}
-
- /**
- * @return the property
- */
- public Object getProperty() {
- return property;
- }
-
- /**
- * @param property
- * the property to set
- */
- public void setProperty(Object property) {
- this.property = property;
- }
-
- public boolean isSameBase(Object base) {
- return (null == base && null == this.base) || (base == this.base);
- }
-
- public boolean isSameProperty(Object property) {
- if (null == this.property) {
- return null == property;
- } else {
- return this.property.equals(property);
+
+ private static Map<Object, GraphValidatorState> getStateMap(FacesContext
context){
+ IdentityHashMap<Object, GraphValidatorState> statesMap =
(IdentityHashMap<Object, GraphValidatorState>)
context.getAttributes().get(STATE_ATTRIBUTE);
+ if(null == statesMap){
+ statesMap = new IdentityHashMap<Object, GraphValidatorState>();
+ context.getAttributes().put(STATE_ATTRIBUTE, statesMap);
}
+ return statesMap;
}
-
- public boolean isSame(Object base, Object property) {
- return isSameBase(base) && isSameProperty(property) && active;
- }
}
\ No newline at end of file
Modified:
trunk/ui/validator/ui/src/main/java/org/richfaces/component/AbstractGraphValidator.java
===================================================================
---
trunk/ui/validator/ui/src/main/java/org/richfaces/component/AbstractGraphValidator.java 2011-03-07
17:31:10 UTC (rev 22076)
+++
trunk/ui/validator/ui/src/main/java/org/richfaces/component/AbstractGraphValidator.java 2011-03-07
20:14:44 UTC (rev 22077)
@@ -20,43 +20,41 @@
*/
package org.richfaces.component;
-import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.util.Collection;
-import java.util.Iterator;
-import javax.el.ELContext;
import javax.el.ValueExpression;
import javax.faces.FacesException;
import javax.faces.application.FacesMessage;
-import javax.faces.component.EditableValueHolder;
-import javax.faces.component.UIComponent;
import javax.faces.component.UIComponentBase;
import javax.faces.context.FacesContext;
import javax.faces.validator.Validator;
+import org.richfaces.application.ServiceTracker;
import org.richfaces.cdk.annotations.Attribute;
import org.richfaces.cdk.annotations.JsfComponent;
import org.richfaces.cdk.annotations.Tag;
import org.richfaces.cdk.annotations.TagType;
-import org.richfaces.el.CapturingELResolver;
-import org.richfaces.el.ELContextWrapper;
+import org.richfaces.log.Logger;
+import org.richfaces.log.RichfacesLogger;
+import org.richfaces.validator.BeanValidatorService;
import org.richfaces.validator.FacesBeanValidator;
-import org.richfaces.validator.GraphValidator;
import org.richfaces.validator.GraphValidatorState;
/**
* JSF component class
*
*/
-@JsfComponent(tag=(a)Tag(name="graphValidator",type=TagType.Facelets))
+@JsfComponent(tag=(a)Tag(name="graphValidator",type=TagType.Facelets, handler =
"org.richfaces.view.facelets.html.GraphValidatorHandler"))
public abstract class AbstractGraphValidator extends UIComponentBase {
public static final String COMPONENT_TYPE =
"org.richfaces.GraphValidator";
public static final String COMPONENT_FAMILY =
"org.richfaces.GraphValidator";
+
+ private static final Logger LOG = RichfacesLogger.COMPONENTS.getLogger();
/**
* Get object for validation
@@ -121,38 +119,26 @@
@Override
public void processDecodes(FacesContext context) {
GraphValidatorState validatorState = null;
- // Detect value EL-expression.
- ValueExpression valueExpression = getValueExpression("value");
- if (null != valueExpression) {
-
- Object value = getValue();
- if (null != value && value instanceof Cloneable) {
+ boolean wasActive = false;
+ Object value = getValue();
+ if (null != value) {
+ validatorState = GraphValidatorState.getState(context, value);
+ if (null != validatorState) {
+ // Reuse old value, if any.
+ wasActive = validatorState.isActive();
+ validatorState.setActive(true);
+ } else if (value instanceof Cloneable) {
try {
- ELContext initialELContext = context.getELContext();
-
- CapturingELResolver capturingELResolver = new
CapturingELResolver(initialELContext.getELResolver());
- Class<?> type =
- valueExpression.getType(new ELContextWrapper(initialELContext,
capturingELResolver));
- if (null != type) {
- validatorState = new GraphValidatorState();
- Method method = getCloneMethod(value.getClass());
- if (!Modifier.isPublic(method.getModifiers())) {
- // Method Object#clone() is protected by default. Make it
public
- // unless developer did it.
- method.setAccessible(true);
- }
- validatorState.setCloned(method.invoke(value));
- validatorState.setBase(capturingELResolver.getBase());
- validatorState.setProperty(capturingELResolver.getProperty());
- validatorState.setActive(true);
-
context.getExternalContext().getRequestMap().put(getStateId(context), validatorState);
- }
+ Method method = getCloneMethod(value.getClass());
+ validatorState = new GraphValidatorState(method.invoke(value));
+ validatorState.setActive(true);
+ GraphValidatorState.setState(context, value, validatorState);
} catch (NoSuchMethodException e) {
- // do nothing, that is really not possible.
+ // do nothing, that is really not possible - clone() impemented in
Object.
} catch (InvocationTargetException e) {
throw new FacesException(e);
} catch (IllegalArgumentException e) {
- // do nothing, that is really not possible.
+ // do nothing, that is really not possible - method has no
arguments.
} catch (IllegalAccessException e) {
throw new FacesException(e);
}
@@ -160,7 +146,7 @@
}
super.processDecodes(context);
if (null != validatorState) {
- validatorState.setActive(false);
+ validatorState.setActive(wasActive);
}
}
@@ -169,71 +155,78 @@
return clazz.getDeclaredMethod("clone");
} catch (NoSuchMethodException e) {
if (null != clazz.getSuperclass()) {
- return getCloneMethod(clazz.getSuperclass());
+ Method method = getCloneMethod(clazz.getSuperclass());
+ if (!Modifier.isPublic(method.getModifiers())) {
+ // Method Object#clone() is protected by default. Make it public
+ // unless developer did it.
+ method.setAccessible(true);
+ }
+ return method;
} else {
throw e;
}
}
}
- protected String getStateId(FacesContext context) {
- String stateId = GraphValidatorState.STATE_ATTRIBUTE_PREFIX +
getClientId(context);
- return stateId;
- }
protected GraphValidatorState getValidatorState(FacesContext context) {
- return (GraphValidatorState)
context.getExternalContext().getRequestMap().get(getStateId(context));
+ Object value = getValue();
+ if (null != value) {
+ return GraphValidatorState.getState(context, value);
+ } else {
+ return null;
+ }
}
@Override
public void processValidators(FacesContext context) {
GraphValidatorState validatorState = getValidatorState(context);
if (null != validatorState) {
+ boolean wasActive = validatorState.isActive();
validatorState.setActive(true);
+ super.processValidators(context);
+ validatorState.setActive(wasActive);
+ if(!context.isValidationFailed()){
+ validateObject(context, validatorState.getCloned());
+ }
+ } else {
+ super.processValidators(context);
}
- super.processValidators(context);
- if (null != validatorState) {
- validatorState.setActive(false);
- validateObject(context, validatorState.getCloned());
- context.getExternalContext().getRequestMap().remove(getStateId(context));
- }
}
@Override
public void processUpdates(FacesContext context) {
super.processUpdates(context);
- Object value = getValue();
- validateObject(context, value);
+ // Validate updated object if it was not done on clone.
+ if (!context.isValidationFailed()) {
+ Object value = getValue();
+ if (null != value) {
+ if (null == GraphValidatorState.getState(context, value)) {
+ validateObject(context, value);
+ }
+ }
+ }
}
private void validateObject(FacesContext context, Object value) {
if (null != value) {
- Validator validator = context.getApplication().createValidator(getType());
- if (validator instanceof GraphValidator) {
- GraphValidator graphValidator = (GraphValidator) validator;
- Collection<String> messages = graphValidator.validateGraph(context,
this, value, getGroups());
- if (null != messages) {
- context.renderResponse();
- // send all validation messages.
- String clientId = getClientId(context);
- for (String msg : messages) {
- // TODO - create Summary message ?
- String summary = null != getSummary() ? getSummary() + msg :
msg;
- context.addMessage(clientId, new
FacesMessage(FacesMessage.SEVERITY_ERROR, summary, msg));
- }
+ Collection<String> messages;
+ BeanValidatorService validatorService =
ServiceTracker.getService(BeanValidatorService.class);
+ messages = validatorService.validateObject(context, value, getGroups());
+ if (!messages.isEmpty()) {
+ context.renderResponse();
+ // send all validation messages.
+ String clientId = getClientId(context);
+ for (String msg : messages) {
+ String summary = null != getSummary() ? getSummary() : msg;
+ context.addMessage(clientId, new
FacesMessage(FacesMessage.SEVERITY_ERROR, summary, msg));
}
-
- } else {
- throw new FacesException("Validator " +
FacesBeanValidator.BEAN_VALIDATOR_TYPE
- + " does not implement GraphValidator");
}
}
}
- @Override
- public void encodeBegin(FacesContext context) throws IOException {
- super.encodeBegin(context);
+ public Validator createChildrenValidator(FacesContext context) {
FacesBeanValidator validator = (FacesBeanValidator)
context.getApplication().createValidator(getType());
validator.setSummary(getSummary());
ValueExpression expression = getValueExpression("groups");
@@ -242,48 +235,7 @@
} else {
validator.setGroups(getGroups());
}
- setupValidators(this, validator);
+ return validator;
}
-
- @Override
- public void encodeChildren(FacesContext context) throws IOException {
- if (isRendered()) {
- for (UIComponent child : getChildren()) {
- if (child.isRendered()) {
- child.encodeAll(context);
- }
- }
- }
- }
-
- private void setupValidators(UIComponent component, Validator validator) {
- Iterator<UIComponent> facetsAndChildren =
component.getFacetsAndChildren();
- while (facetsAndChildren.hasNext()) {
- UIComponent child = facetsAndChildren.next();
- if (child instanceof EditableValueHolder) {
- EditableValueHolder input = (EditableValueHolder) child;
- setupValidator(input, validator);
- }
- setupValidators(child, validator);
- }
- }
-
- /**
- * @param input
- */
- private void setupValidator(EditableValueHolder input, Validator validator) {
- Validator[] validators = input.getValidators();
- for (int i = 0; i < validators.length; i++) {
- if (validators[i].getClass().equals(validator.getClass())) {
- return;
- }
- }
- input.addValidator(validator);
- }
-
- @Override
- public boolean getRendersChildren() {
- return true;
- }
-
+
}
Modified:
trunk/ui/validator/ui/src/main/java/org/richfaces/component/behavior/ClientValidatorImpl.java
===================================================================
---
trunk/ui/validator/ui/src/main/java/org/richfaces/component/behavior/ClientValidatorImpl.java 2011-03-07
17:31:10 UTC (rev 22076)
+++
trunk/ui/validator/ui/src/main/java/org/richfaces/component/behavior/ClientValidatorImpl.java 2011-03-07
20:14:44 UTC (rev 22077)
@@ -31,6 +31,7 @@
import javax.el.ValueExpression;
import javax.faces.FacesException;
import javax.faces.application.Application;
+import javax.faces.application.FacesMessage;
import javax.faces.component.ActionSource;
import javax.faces.component.EditableValueHolder;
import javax.faces.component.NamingContainer;
@@ -54,6 +55,7 @@
import org.richfaces.cdk.annotations.Tag;
import org.richfaces.cdk.annotations.TagType;
import org.richfaces.component.ClientSideMessage;
+import org.richfaces.javascript.JavaScriptService;
import org.richfaces.log.Logger;
import org.richfaces.log.RichfacesLogger;
import org.richfaces.renderkit.html.ClientValidatorRenderer;
@@ -116,12 +118,10 @@
if(partialViewContext.isAjaxRequest()){
UIComponent component = event.getComponent();
if(component instanceof EditableValueHolder){
- EditableValueHolder input = (EditableValueHolder) component;
- Set<UIComponent> messages = getMessages(facesContext, component);
- Collection<String> renderIds = partialViewContext.getRenderIds();
- for (UIComponent uiComponent : messages) {
- renderIds.add(uiComponent.getClientId(facesContext));
- }
+ String clientId = component.getClientId(facesContext);
+ Iterator<FacesMessage> messages =
facesContext.getMessages(clientId);
+ JavaScriptService javaScriptService =
ServiceTracker.getService(JavaScriptService.class);
+ javaScriptService.addPageReadyScript(facesContext, new
MessageUpdateScript(clientId,messages));
}
}
super.broadcast(event);
@@ -245,7 +245,7 @@
}
if(null != converter){
FacesConverterService converterService =
ServiceTracker.getService(facesContext, FacesConverterService.class);
- return converterService.getConverterDescription(facesContext,
converter);
+ return converterService.getConverterDescription(facesContext, input,
converter);
} else {
return null;
}
@@ -282,18 +282,20 @@
Validator[] facesValidators = input.getValidators();
FacesContext facesContext = context.getFacesContext();
if (facesValidators.length > 0) {
+ boolean beanValidatorsProcessed = false;
FacesValidatorService facesValidatorService =
ServiceTracker.getService(facesContext,
FacesValidatorService.class);
for (Validator validator : facesValidators) {
if (validator instanceof BeanValidator || validator instanceof
FacesBeanValidator) {
ValueExpression valueExpression =
component.getValueExpression(VALUE);
- if (null != valueExpression) {
+ if (null != valueExpression && !beanValidatorsProcessed)
{
BeanValidatorService beanValidatorService =
ServiceTracker.getService(facesContext,
BeanValidatorService.class);
validators.addAll(beanValidatorService.getConstrains(facesContext, valueExpression,
getGroups()));
+ beanValidatorsProcessed = true;
}
} else {
-
validators.add(facesValidatorService.getValidatorDescription(facesContext, validator));
+
validators.add(facesValidatorService.getValidatorDescription(facesContext, input,
validator));
}
}
}
Copied:
trunk/ui/validator/ui/src/main/java/org/richfaces/component/behavior/MessageUpdateScript.java
(from rev 22076,
branches/4.0.X/ui/validator/ui/src/main/java/org/richfaces/component/behavior/MessageUpdateScript.java)
===================================================================
---
trunk/ui/validator/ui/src/main/java/org/richfaces/component/behavior/MessageUpdateScript.java
(rev 0)
+++
trunk/ui/validator/ui/src/main/java/org/richfaces/component/behavior/MessageUpdateScript.java 2011-03-07
20:14:44 UTC (rev 22077)
@@ -0,0 +1,45 @@
+package org.richfaces.component.behavior;
+
+import java.io.IOException;
+import java.util.Iterator;
+
+import javax.faces.application.FacesMessage;
+
+
+import org.ajax4jsf.javascript.JSFunction;
+import org.ajax4jsf.javascript.ScriptString;
+import org.ajax4jsf.javascript.ScriptStringBase;
+import org.richfaces.javascript.Message;
+
+import com.google.common.base.Function;
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.Iterators;
+
+public class MessageUpdateScript extends ScriptStringBase implements ScriptString {
+
+ private static final Function<? super FacesMessage, Message>
MESSAGES_TRANSFORMER = new Function<FacesMessage, Message>() {
+
+ public Message apply(FacesMessage msg) {
+ return new Message(msg);
+ }
+ };
+ private final ImmutableList<Message> messages;
+ private final String clientId;
+
+ public MessageUpdateScript(String clientId,Iterator<FacesMessage> messages) {
+ this.clientId = clientId;
+ this.messages = ImmutableList.copyOf(Iterators.transform(messages,
MESSAGES_TRANSFORMER));
+ }
+
+ public void appendScript(Appendable target) throws IOException {
+ JSFunction resetMessages = new
JSFunction("RichFaces.csv.clearMessage",clientId);
+ resetMessages.appendScript(target);
+ target.append(';');
+ for (Message message : messages) {
+ JSFunction sendMessage = new
JSFunction("RichFaces.csv.sendMessage",clientId,message);
+ sendMessage.appendScript(target);
+ target.append(';');
+ }
+ }
+
+}
Modified: trunk/ui/validator/ui/src/main/java/org/richfaces/el/CapturingELContext.java
===================================================================
---
trunk/ui/validator/ui/src/main/java/org/richfaces/el/CapturingELContext.java 2011-03-07
17:31:10 UTC (rev 22076)
+++
trunk/ui/validator/ui/src/main/java/org/richfaces/el/CapturingELContext.java 2011-03-07
20:14:44 UTC (rev 22077)
@@ -4,14 +4,21 @@
package org.richfaces.el;
import java.beans.FeatureDescriptor;
+import java.util.Collection;
import java.util.Iterator;
import java.util.Locale;
+import java.util.Map;
import javax.el.ELContext;
import javax.el.ELResolver;
import javax.el.FunctionMapper;
+import javax.el.ValueExpression;
import javax.el.VariableMapper;
+import javax.faces.context.FacesContext;
+import javax.faces.el.CompositeComponentExpressionHolder;
+import org.richfaces.validator.GraphValidatorState;
+
/**
* This class wraps original ELContext and capture whole call stack to the target object
so it could be used to extract
* semantic information like annotations or Jena Model properties.
@@ -36,6 +43,37 @@
return reference;
}
+ private boolean isContainerObject(Object base) {
+ return base instanceof Collection || base instanceof Map ||
base.getClass().isArray();
+ }
+
+ public boolean hasReferenceExpression() {
+ return reference != null && reference.getBase() instanceof
CompositeComponentExpressionHolder;
+ }
+
+ public ValueExpression getReferenceExpression() {
+ CompositeComponentExpressionHolder expressionHolder =
(CompositeComponentExpressionHolder) reference.getBase();
+ return expressionHolder.getExpression(reference.getProperty().toString());
+ }
+
+ public ValueDescriptor getDescriptor() {
+ ValueReference localReference = reference;
+
+ while (true) {
+ if (localReference == null || localReference.getBase() == null ||
localReference.getProperty() == null) {
+ return null;
+ }
+
+ Object base = localReference.getBase();
+
+ if (isContainerObject(base) && localReference.hasNext()) {
+ localReference = localReference.next();
+ } else {
+ return new ValueDescriptor(base.getClass(),
localReference.getProperty().toString());
+ }
+ }
+ }
+
/*
* (non-Javadoc)
*
@@ -88,6 +126,7 @@
private final class InterceptingResolver extends ELResolver {
private ELResolver delegate;
+ private boolean clonedObject;
public InterceptingResolver(ELResolver delegate) {
this.delegate = delegate;
@@ -97,6 +136,11 @@
@Override
public void setValue(ELContext context, Object base, Object property, Object
value) {
if (base != null) {
+ // TODO - detect value object from inderect references ( e.g. data table
variables ).
+ if (this.clonedObject) {
+ delegate.setValue(context, base, property, value);
+ }
+
context.setPropertyResolved(true);
reference = new ValueReference(base, property, reference);
}
@@ -107,7 +151,16 @@
@Override
public Object getValue(ELContext context, Object base, Object property) {
reference = new ValueReference(base, property, reference);
- return delegate.getValue(context, base, property);
+ Object value = delegate.getValue(context, base, property);
+ if (null != value && context.isPropertyResolved()) {
+ FacesContext facesContext = (FacesContext)
context.getContext(FacesContext.class);
+ Object clone = GraphValidatorState.getActiveClone(facesContext, value);
+ if (null != clone) {
+ this.clonedObject = true;
+ return clone;
+ }
+ }
+ return value;
}
@Override
Modified:
trunk/ui/validator/ui/src/main/java/org/richfaces/el/ValueExpressionAnalayserImpl.java
===================================================================
---
trunk/ui/validator/ui/src/main/java/org/richfaces/el/ValueExpressionAnalayserImpl.java 2011-03-07
17:31:10 UTC (rev 22076)
+++
trunk/ui/validator/ui/src/main/java/org/richfaces/el/ValueExpressionAnalayserImpl.java 2011-03-07
20:14:44 UTC (rev 22077)
@@ -1,25 +1,96 @@
package org.richfaces.el;
+import javax.el.ELContext;
import javax.el.ELException;
import javax.el.ValueExpression;
import javax.faces.context.FacesContext;
public class ValueExpressionAnalayserImpl implements ValueExpressionAnalayser {
- public ValueDescriptor getPropertyDescriptor(FacesContext context, ValueExpression
expression) throws ELException {
- if(null == context || null == expression){
- throw new NullPointerException();
+ private abstract static class ValueResolutionCommand {
+
+ private ValueDescriptor valueDescriptor;
+
+ public ValueDescriptor getValueDescriptor() {
+ return valueDescriptor;
}
- CapturingELContext capturingContext = new
CapturingELContext(context.getELContext());
- Class<?> type = expression.getType(capturingContext);
- ValueReference reference = capturingContext.getReference();
- if(null != reference && null != reference.getBase() && null !=
reference.getProperty()){
- // TODO - detect arrays, maps and lists. Check JSF implementation code -
seems that Mojarra dosn't validate such fields.
- ValueDescriptor descriptor = new
ValueDescriptor(reference.getBase().getClass(),reference.getProperty().toString(),type);
- return descriptor;
- } else {
- throw new ELException("Cannot determine property for expression
"+expression.getExpressionString());
+
+ void setValueDescriptor(ValueDescriptor valueDescriptor) {
+ this.valueDescriptor = valueDescriptor;
}
+
+ public abstract void resolve(ValueExpression expression, ELContext context);
+
}
+
+ private static final class GetTypeCommand extends ValueResolutionCommand {
+ @Override
+ public void resolve(ValueExpression expression, ELContext context) {
+ expression.getType(context);
+ }
+ }
+
+ private static final class SetValueCommand extends ValueResolutionCommand {
+
+ private Object value;
+
+ public SetValueCommand(Object value) {
+ super();
+ this.value = value;
+ }
+
+ @Override
+ public void resolve(ValueExpression expression, ELContext context) {
+ expression.setValue(context, value);
+ }
+
+ }
+
+ private void checkNotNull(FacesContext context, ValueExpression expression) {
+ if (context == null) {
+ throw new NullPointerException("facesContext");
+ }
+
+ if (expression == null) {
+ throw new NullPointerException("expression");
+ }
+ }
+
+ private void resolveValue(FacesContext context, ValueExpression initialExpression,
ValueResolutionCommand command) throws ELException {
+ checkNotNull(context, initialExpression);
+
+ ValueExpression expression = initialExpression;
+
+ while (expression != null) {
+ CapturingELContext capturingContext = new
CapturingELContext(context.getELContext());
+ command.resolve(expression, capturingContext);
+
+ if (capturingContext.hasReferenceExpression()) {
+ expression = capturingContext.getReferenceExpression();
+ } else {
+ ValueDescriptor result = capturingContext.getDescriptor();
+
+ if (result == null) {
+ throw new ELException("Cannot determine property for expression
" + initialExpression.getExpressionString());
+ }
+
+ command.setValueDescriptor(result);
+ break;
+ }
+ }
+ }
+
+ public ValueDescriptor getPropertyDescriptor(FacesContext context, ValueExpression
expression) throws ELException {
+ ValueResolutionCommand command = new GetTypeCommand();
+ resolveValue(context, expression, command);
+ return command.getValueDescriptor();
+ }
+
+ public ValueDescriptor updateValueAndGetPropertyDescriptor(FacesContext context,
ValueExpression expression, Object newValue) throws ELException {
+ ValueResolutionCommand command = new SetValueCommand(newValue);
+ resolveValue(context, expression, command);
+ return command.getValueDescriptor();
+ }
+
}
Modified:
trunk/ui/validator/ui/src/main/java/org/richfaces/javascript/ClientScriptServiceImpl.java
===================================================================
---
trunk/ui/validator/ui/src/main/java/org/richfaces/javascript/ClientScriptServiceImpl.java 2011-03-07
17:31:10 UTC (rev 22076)
+++
trunk/ui/validator/ui/src/main/java/org/richfaces/javascript/ClientScriptServiceImpl.java 2011-03-07
20:14:44 UTC (rev 22077)
@@ -3,9 +3,12 @@
*/
package org.richfaces.javascript;
+import java.util.Collections;
import java.util.List;
import java.util.Map;
+import java.util.concurrent.ConcurrentMap;
+import javax.faces.FacesException;
import javax.faces.application.Resource;
import javax.faces.application.ResourceDependency;
import javax.faces.application.ResourceHandler;
@@ -14,7 +17,10 @@
import org.richfaces.component.util.Strings;
import org.richfaces.resource.ResourceKey;
+import com.google.common.base.Function;
+import com.google.common.collect.ComputationException;
import com.google.common.collect.Lists;
+import com.google.common.collect.MapMaker;
/**
* @author asmirnov
@@ -25,11 +31,42 @@
private static final String TEXT_JAVASCRIPT = "text/javascript";
private static final String ORG_RICHFACES_CSV = "org.richfaces.csv";
+
+ private static final LibraryFunction NO_SCRIPT = new LibraryFunction() {
+
+ public Iterable<ResourceKey> getResources() {
+ return Collections.emptySet();
+ }
+
+ public String getName() {
+ return null;
+ }
+ };
+ private static final Function<Class<?>, ? extends LibraryFunction>
RESOURCE_SCRIPT_FUNCTION = new Function<Class<?>, LibraryFunction>() {
+
+ public LibraryFunction apply(Class<?> arg0) {
+ return getScriptResource(FacesContext.getCurrentInstance(), arg0);
+ }
+ };
+
+ private static final Function<Class<?>, ? extends LibraryFunction>
ANNOTATION_SCRIPT_FUNCTION = new Function<Class<?>, LibraryFunction>() {
+
+ public LibraryFunction apply(Class<?> arg0) {
+ return getScriptFromAnnotation(arg0);
+ }
+ };
+
+ private final ConcurrentMap<Class<?>, LibraryFunction> resourcesMapping;
+
+ private final ConcurrentMap<Class<?>, LibraryFunction>
annotationsMapping;
+
private final Map<Class<?>, LibraryFunction> defaultMapping;
public ClientScriptServiceImpl(Map<Class<?>, LibraryFunction>
defaultMapping) {
this.defaultMapping = defaultMapping;
+ resourcesMapping = new
MapMaker().initialCapacity(10).makeComputingMap(RESOURCE_SCRIPT_FUNCTION);
+ annotationsMapping = new
MapMaker().initialCapacity(10).makeComputingMap(ANNOTATION_SCRIPT_FUNCTION);
}
/*
@@ -41,20 +78,30 @@
if (null == facesContext || null == javaClass) {
throw new NullPointerException();
}
- LibraryFunction function;
- try {
- function = getScriptResource(facesContext, javaClass);
- } catch (ScriptNotFoundException e) {
+ LibraryFunction function = getFromComputationMap(resourcesMapping, javaClass);
+ if(NO_SCRIPT == function) {
if (defaultMapping.containsKey(javaClass)) {
function = defaultMapping.get(javaClass);
} else {
- function = getScriptFromAnnotation(javaClass);
+ function = getFromComputationMap(annotationsMapping, javaClass);
}
}
+ if(NO_SCRIPT == function) {
+ throw new ScriptNotFoundException("No client-side script for class
"+javaClass.getName());
+ }
return function;
}
+
+ private LibraryFunction getFromComputationMap(ConcurrentMap<Class<?>,
LibraryFunction> map, Class<?> clazz){
+ try {
+ return map.get(clazz);
+ } catch (ComputationException e) {
+ Throwable cause = e.getCause();
+ throw new FacesException(cause);
+ }
+ }
- private LibraryFunction getScriptFromAnnotation(Class<?> javaClass) throws
ScriptNotFoundException {
+ private static LibraryFunction getScriptFromAnnotation(Class<?> javaClass) {
if (javaClass.isAnnotationPresent(ClientSideScript.class)) {
ClientSideScript clientSideScript =
javaClass.getAnnotation(ClientSideScript.class);
List<ResourceKey> resources = Lists.newArrayList();
@@ -63,12 +110,11 @@
}
return new LibraryFunctionImplementation(clientSideScript.function(),
resources);
} else {
- throw new ScriptNotFoundException();
+ return NO_SCRIPT;
}
}
- private LibraryFunction getScriptResource(FacesContext facesContext, Class<?>
javaClass)
- throws ScriptNotFoundException {
+ private static LibraryFunction getScriptResource(FacesContext facesContext,
Class<?> javaClass){
ResourceHandler resourceHandler =
facesContext.getApplication().getResourceHandler();
String resourceName = javaClass.getSimpleName() + ".js";
Resource facesResource = resourceHandler.createResource(resourceName,
ORG_RICHFACES_CSV, TEXT_JAVASCRIPT);
@@ -76,7 +122,7 @@
final String functionName =
Strings.firstToLowerCase(javaClass.getSimpleName());
return new LibraryFunctionImplementation(functionName,resourceName,
ORG_RICHFACES_CSV);
} else {
- throw new ScriptNotFoundException();
+ return NO_SCRIPT;
}
}
Modified:
trunk/ui/validator/ui/src/main/java/org/richfaces/renderkit/html/AjaxOnlyScript.java
===================================================================
---
trunk/ui/validator/ui/src/main/java/org/richfaces/renderkit/html/AjaxOnlyScript.java 2011-03-07
17:31:10 UTC (rev 22076)
+++
trunk/ui/validator/ui/src/main/java/org/richfaces/renderkit/html/AjaxOnlyScript.java 2011-03-07
20:14:44 UTC (rev 22077)
@@ -1,15 +1,18 @@
package org.richfaces.renderkit.html;
import java.io.IOException;
-import java.util.Collections;
import org.richfaces.resource.ResourceKey;
+import com.google.common.collect.ImmutableSet;
+
public class AjaxOnlyScript extends ValidatorScriptBase {
- public static final Iterable<ResourceKey> AJAX_LIBRARIES =
Collections.singleton(ResourceKey.create("ajax.reslib",
- "org.richfaces"));
+ public static final ResourceKey AJAX_RESOURCE =
ResourceKey.create("ajax.reslib",
+ "org.richfaces");
+ public static final Iterable<ResourceKey> AJAX_LIBRARIES =
ImmutableSet.of(AJAX_RESOURCE,ClientOnlyScript.CSV_RESOURCE);
+
private final String ajaxScript;
public AjaxOnlyScript(String ajaxScript) {
Modified:
trunk/ui/validator/ui/src/main/java/org/richfaces/renderkit/html/ClientAndAjaxScript.java
===================================================================
---
trunk/ui/validator/ui/src/main/java/org/richfaces/renderkit/html/ClientAndAjaxScript.java 2011-03-07
17:31:10 UTC (rev 22076)
+++
trunk/ui/validator/ui/src/main/java/org/richfaces/renderkit/html/ClientAndAjaxScript.java 2011-03-07
20:14:44 UTC (rev 22077)
@@ -5,7 +5,8 @@
import org.richfaces.resource.ResourceKey;
-import com.google.common.collect.Iterables;
+import com.google.common.collect.ImmutableSet;
+import com.google.common.collect.ImmutableSet.Builder;
public class ClientAndAjaxScript extends ClientOnlyScript{
@@ -19,7 +20,10 @@
Collection<? extends LibraryScriptFunction> validatorScripts, String
ajaxScript) {
super(clientSideConverterScript,validatorScripts);
this.ajaxScript = ajaxScript;
- resources =
Iterables.concat(AjaxOnlyScript.AJAX_LIBRARIES,super.getResources());
+ Builder<ResourceKey> builder = ImmutableSet.<ResourceKey>builder();
+ builder.add(AjaxOnlyScript.AJAX_RESOURCE);
+ builder.addAll(super.getResources());
+ resources = builder.build();
}
Modified:
trunk/ui/validator/ui/src/main/java/org/richfaces/renderkit/html/ClientOnlyScript.java
===================================================================
---
trunk/ui/validator/ui/src/main/java/org/richfaces/renderkit/html/ClientOnlyScript.java 2011-03-07
17:31:10 UTC (rev 22076)
+++
trunk/ui/validator/ui/src/main/java/org/richfaces/renderkit/html/ClientOnlyScript.java 2011-03-07
20:14:44 UTC (rev 22077)
@@ -15,7 +15,7 @@
public class ClientOnlyScript extends ValidatorScriptBase {
- private static final ResourceKey CSV_RESOURCE =
ResourceKey.create("csv.reslib", "org.richfaces");
+ public static final ResourceKey CSV_RESOURCE =
ResourceKey.create("csv.reslib", "org.richfaces");
protected final LibraryScriptFunction converter;
protected final ImmutableList<? extends LibraryScriptFunction> validators;
private final ImmutableSet<ResourceKey> resources;
@@ -26,13 +26,13 @@
this.converter = clientSideConverterScript;
this.validators = ImmutableList.copyOf(validatorScripts);
LinkedHashSet<ResourceKey> resources = Sets.newLinkedHashSet();
+ resources.add(CSV_RESOURCE);
if (null != converter) {
Iterables.addAll(resources, converter.getResources());
}
for (LibraryScriptFunction scriptString : validators) {
Iterables.addAll(resources, scriptString.getResources());
}
- resources.add(CSV_RESOURCE);
this.resources = ImmutableSet.copyOf(resources);
}
Modified:
trunk/ui/validator/ui/src/main/java/org/richfaces/validator/BeanValidatorServiceImpl.java
===================================================================
---
trunk/ui/validator/ui/src/main/java/org/richfaces/validator/BeanValidatorServiceImpl.java 2011-03-07
17:31:10 UTC (rev 22076)
+++
trunk/ui/validator/ui/src/main/java/org/richfaces/validator/BeanValidatorServiceImpl.java 2011-03-07
20:14:44 UTC (rev 22077)
@@ -3,23 +3,17 @@
*/
package org.richfaces.validator;
-import java.beans.FeatureDescriptor;
import java.lang.annotation.Annotation;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
-import java.util.EmptyStackException;
import java.util.HashSet;
-import java.util.Iterator;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
-import java.util.Stack;
-import javax.el.ELContext;
import javax.el.ELException;
-import javax.el.ELResolver;
import javax.el.ValueExpression;
import javax.faces.FacesException;
import javax.faces.application.FacesMessage;
@@ -30,7 +24,6 @@
import javax.validation.metadata.ElementDescriptor.ConstraintFinder;
import javax.validation.metadata.PropertyDescriptor;
-import org.richfaces.el.ELContextWrapper;
import org.richfaces.el.ValueDescriptor;
import org.richfaces.el.ValueExpressionAnalayser;
@@ -64,6 +57,11 @@
Class<?>... groups) {
try {
ValueDescriptor propertyDescriptor = analayser.getPropertyDescriptor(context,
expression);
+
+ if (propertyDescriptor == null) {
+ return Collections.emptySet();
+ }
+
return processBeanAttribute(context, propertyDescriptor, groups);
} catch (ELException e) {
return Collections.emptySet();
@@ -147,66 +145,36 @@
public Collection<String> validateExpression(FacesContext context,
ValueExpression expression, Object newValue,
Class<?>... groups) {
+
if (null == context) {
throw new FacesException(INPUT_PARAMETERS_IS_NOT_CORRECT);
}
- Collection<String> validationMessages = Collections.emptySet();
+
+ Collection<String> validationMessages = null;
if (null != expression) {
- ELContext elContext = context.getELContext();
- ValidationResolver validationResolver =
- createValidationResolver(context, elContext.getELResolver(), groups);
- ELContextWrapper wrappedElContext = new ELContextWrapper(elContext,
validationResolver);
+ ValueDescriptor valueDescriptor;
try {
- expression.setValue(wrappedElContext, newValue);
+ valueDescriptor = analayser.updateValueAndGetPropertyDescriptor(context,
expression, newValue);
} catch (ELException e) {
throw new FacesException(e);
}
- if (!validationResolver.isValid()) {
- validationMessages = validationResolver.getValidationMessages();
+
+ if (valueDescriptor != null) {
+ validationMessages = validate(context, valueDescriptor.getBeanType(),
valueDescriptor.getName(), newValue, groups);
}
+
}
+
+ if (validationMessages == null) {
+ validationMessages = Collections.emptySet();
+ }
+
return validationMessages;
}
- protected ValidationResolver createValidationResolver(FacesContext context,
ELResolver parent, Class<?>[] groups) {
- return new ValidationResolver(parent, context, groups);
- }
/**
- * @author asmirnov
- *
- */
- protected static class BasePropertyPair {
- private final Object base;
- private final Object property;
-
- /**
- * @param base
- * @param property
- */
- public BasePropertyPair(Object base, Object property) {
- this.base = base;
- this.property = property;
- }
-
- /**
- * @return the base
- */
- public Object getBase() {
- return base;
- }
-
- /**
- * @return the property
- */
- public Object getProperty() {
- return property;
- }
-
- }
-
- /**
* Class for identify validator instance by locale
*
* @author amarkhel
@@ -277,165 +245,13 @@
}
- /**
- * Wrapper class for a {@link ELResolver}. For a setValue method, perform validation
instead of real assignment.
- *
- * @author asmirnov
- *
- */
- final class ValidationResolver extends ELResolver {
- /**
- * Original resolver.
- */
- private final ELResolver parent;
-
- private boolean valid = true;
-
- private Collection<String> validationMessages = null;
-
- private Stack<BasePropertyPair> valuesStack;
-
- private Class<?>[] groups;
-
- private FacesContext facesContext;
-
- private boolean clonedObject = false;
-
- /**
- * @param parent
- * @param context
- */
- public ValidationResolver(ELResolver parent, FacesContext context,
Class<?>[] groups) {
- this.parent = parent;
- this.valuesStack = new Stack<BasePropertyPair>();
- this.groups = groups;
- this.facesContext = context;
- }
-
- public boolean isValid() {
- return valid;
- }
-
- /**
- * @param context
- * @param base
- * @return
- * @see javax.el.ELResolver#getCommonPropertyType(javax.el.ELContext,
java.lang.Object)
- */
- public Class<?> getCommonPropertyType(ELContext context, Object base) {
- return parent.getCommonPropertyType(context, base);
- }
-
- /**
- * @param context
- * @param base
- * @return
- * @see javax.el.ELResolver#getFeatureDescriptors(javax.el.ELContext,
java.lang.Object)
- */
- public Iterator<FeatureDescriptor> getFeatureDescriptors(ELContext context,
Object base) {
- return parent.getFeatureDescriptors(context, base);
- }
-
- /**
- * @param context
- * @param base
- * @param property
- * @return
- * @see javax.el.ELResolver#getType(javax.el.ELContext, java.lang.Object,
java.lang.Object)
- */
- public Class<?> getType(ELContext context, Object base, Object property) {
- return parent.getType(context, base, property);
- }
-
- /**
- * @param context
- * @param base
- * @param property
- * @return
- * @see javax.el.ELResolver#getValue(javax.el.ELContext, java.lang.Object,
java.lang.Object)
- */
- public Object getValue(ELContext context, Object base, Object property) {
- Object value = ClonedObjectResolver.resolveCloned(context, base, property);
- if (null != value) {
- this.clonedObject = true;
- context.setPropertyResolved(true);
- } else {
- value = parent.getValue(context, base, property);
- }
- valuesStack.push(new BasePropertyPair(base, property));
- return value;
- }
-
- /**
- * @param context
- * @param base
- * @param property
- * @return
- * @see javax.el.ELResolver#isReadOnly(javax.el.ELContext, java.lang.Object,
java.lang.Object)
- */
- public boolean isReadOnly(ELContext context, Object base, Object property) {
- return parent.isReadOnly(context, base, property);
- }
-
- /**
- * @param context
- * @param base
- * @param property
- * @param value
- * @see javax.el.ELResolver#setValue(javax.el.ELContext, java.lang.Object,
java.lang.Object, java.lang.Object)
- */
- public void setValue(ELContext context, Object base, Object property, Object
value) {
- if (null != base && null != property) {
- // TODO - detect value object from inderect references ( e.g. data table
variables ).
- if (this.clonedObject) {
- parent.setValue(context, base, property, value);
- }
- context.setPropertyResolved(true);
- // For Arrays, Collection or Map use parent base and property.
- BasePropertyPair basePropertyPair = lookupBeanProperty(new
BasePropertyPair(base, property));
- base = basePropertyPair.getBase();
- property = basePropertyPair.getProperty();
- if (null != base && null != property) {
- //
https://jira.jboss.org/jira/browse/RF-4034
- // apache el looses locale information during value
- // resolution,
- // so we use our own
- validationMessages = validate(facesContext, base,
property.toString(), value, groups);
- valid = null == validationMessages || 0 ==
validationMessages.size();
-
- }
- }
- }
-
- private BasePropertyPair lookupBeanProperty(BasePropertyPair pair) {
- Object base = pair.getBase();
- if (null != base && (base instanceof Collection || base instanceof
Map || base.getClass().isArray())) {
- try {
- pair = lookupBeanProperty(valuesStack.pop());
- } catch (EmptyStackException e) {
- // Do nothing, this is a first item.
- }
- }
- return pair;
- }
-
- /**
- * @return the validationMessages
- */
- public Collection<String> getValidationMessages() {
- return validationMessages;
- }
-
- }
-
- protected Collection<String> validate(FacesContext facesContext, Object base,
String property, Object value,
+ protected Collection<String> validate(FacesContext facesContext, Class<?>
beanType, String property, Object value,
Class<?>[] groups) {
- @SuppressWarnings("rawtypes")
- Class beanType = base.getClass();
+
@SuppressWarnings("unchecked")
Set<ConstraintViolation<Object>> constrains =
- getValidator(facesContext).validateValue(beanType, property, value,
getGroups(groups));
+ getValidator(facesContext).validateValue((Class<Object>) beanType,
property, value, getGroups(groups));
return extractMessages(constrains);
}
@@ -450,13 +266,15 @@
}
private Collection<String>
extractMessages(Set<ConstraintViolation<Object>> violations) {
- Collection<String> messages = null;
+ Collection<String> messages;
if (null != violations && violations.size() > 0) {
messages = new ArrayList<String>(violations.size());
for (ConstraintViolation<? extends Object> constraintViolation :
violations) {
messages.add(constraintViolation.getMessage());
}
+ } else {
+ messages = Collections.emptySet();
}
return messages;
}
Deleted:
trunk/ui/validator/ui/src/main/java/org/richfaces/validator/ClonedObjectResolver.java
===================================================================
---
trunk/ui/validator/ui/src/main/java/org/richfaces/validator/ClonedObjectResolver.java 2011-03-07
17:31:10 UTC (rev 22076)
+++
trunk/ui/validator/ui/src/main/java/org/richfaces/validator/ClonedObjectResolver.java 2011-03-07
20:14:44 UTC (rev 22077)
@@ -1,110 +0,0 @@
-/**
- *
- */
-package org.richfaces.validator;
-
-import java.beans.FeatureDescriptor;
-import java.util.Iterator;
-import java.util.Map;
-
-import javax.el.ELContext;
-import javax.el.ELResolver;
-import javax.faces.context.FacesContext;
-
-
-
-/**
- * @author asmirnov
- *
- */
-public class ClonedObjectResolver extends ELResolver {
-
- /*
- * (non-Javadoc)
- *
- * @see javax.el.ELResolver#getCommonPropertyType(javax.el.ELContext,
java.lang.Object)
- */
- @Override
- public Class<?> getCommonPropertyType(ELContext context, Object base) {
- // Do nothing
- return null;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see javax.el.ELResolver#getFeatureDescriptors(javax.el.ELContext,
java.lang.Object)
- */
- @Override
- public Iterator<FeatureDescriptor> getFeatureDescriptors(ELContext context,
Object base) {
- // do nothing
- return null;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see javax.el.ELResolver#getType(javax.el.ELContext, java.lang.Object,
java.lang.Object)
- */
- @Override
- public Class<?> getType(ELContext context, Object base, Object property) {
- Object cloned = resolveCloned(context, base, property);
- if (null != cloned) {
- context.setPropertyResolved(true);
- return cloned.getClass();
- }
- return null;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see javax.el.ELResolver#getValue(javax.el.ELContext, java.lang.Object,
java.lang.Object)
- */
- @Override
- public Object getValue(ELContext context, Object base, Object property) {
- Object cloned = resolveCloned(context, base, property);
- if (null != cloned) {
- context.setPropertyResolved(true);
- }
- return cloned;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see javax.el.ELResolver#isReadOnly(javax.el.ELContext, java.lang.Object,
java.lang.Object)
- */
- @Override
- public boolean isReadOnly(ELContext context, Object base, Object property) {
- // TODO Auto-generated method stub
- return false;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see javax.el.ELResolver#setValue(javax.el.ELContext, java.lang.Object,
java.lang.Object, java.lang.Object)
- */
- @Override
- public void setValue(ELContext context, Object base, Object property, Object value)
{
- // TODO Auto-generated method stub
-
- }
-
- public static Object resolveCloned(ELContext context, Object base, Object property)
{
- if (null != base || null != property) {
- FacesContext facesContext = FacesContext.getCurrentInstance();
- Map<String, Object> requestMap =
facesContext.getExternalContext().getRequestMap();
- for (String key : requestMap.keySet()) {
- if (null != key &&
key.startsWith(GraphValidatorState.STATE_ATTRIBUTE_PREFIX)) {
- GraphValidatorState state = (GraphValidatorState)
requestMap.get(key);
- if (state.isSame(base, property)) {
- return state.getCloned();
- }
- }
- }
- }
- return null;
- }
-}
Modified:
trunk/ui/validator/ui/src/main/java/org/richfaces/validator/ConverterServiceImpl.java
===================================================================
---
trunk/ui/validator/ui/src/main/java/org/richfaces/validator/ConverterServiceImpl.java 2011-03-07
17:31:10 UTC (rev 22076)
+++
trunk/ui/validator/ui/src/main/java/org/richfaces/validator/ConverterServiceImpl.java 2011-03-07
20:14:44 UTC (rev 22077)
@@ -5,6 +5,7 @@
import javax.faces.application.FacesMessage;
+import javax.faces.component.EditableValueHolder;
import javax.faces.component.UIInput;
import javax.faces.context.FacesContext;
import javax.faces.convert.BigDecimalConverter;
@@ -37,9 +38,9 @@
* @see
org.richfaces.validator.FacesConverterService#getConverterDescription(javax.faces.context.FacesContext,
* javax.faces.convert.Converter)
*/
- public ConverterDescriptor getConverterDescription(FacesContext context, Converter
converter) {
+ public ConverterDescriptor getConverterDescription(FacesContext context,
EditableValueHolder input, Converter converter) {
// determine converter message.
- FacesMessage message = getMessage(context, converter);
+ FacesMessage message = getMessage(context, converter, input);
ConverterDescriptorImpl descriptor = new
ConverterDescriptorImpl(converter.getClass(), message);
fillParameters(descriptor, converter);
descriptor.makeImmutable();
Modified:
trunk/ui/validator/ui/src/main/java/org/richfaces/validator/FacesBeanValidator.java
===================================================================
---
trunk/ui/validator/ui/src/main/java/org/richfaces/validator/FacesBeanValidator.java 2011-03-07
17:31:10 UTC (rev 22076)
+++
trunk/ui/validator/ui/src/main/java/org/richfaces/validator/FacesBeanValidator.java 2011-03-07
20:14:44 UTC (rev 22077)
@@ -37,8 +37,6 @@
import org.richfaces.application.ServiceTracker;
import org.richfaces.cdk.annotations.JsfValidator;
-import org.richfaces.cdk.annotations.Tag;
-import org.richfaces.cdk.annotations.TagType;
import com.google.common.base.Strings;
@@ -48,7 +46,7 @@
* @author asmirnov
*
*/
-@JsfValidator(id=FacesBeanValidator.BEAN_VALIDATOR_TYPE,tag=(a)Tag(name="beanValidator",type=TagType.Facelets))
+(a)JsfValidator(id=FacesBeanValidator.BEAN_VALIDATOR_TYPE)
public class FacesBeanValidator implements Serializable, Validator, GraphValidator {
public static final String BEAN_VALIDATOR_TYPE =
"org.richfaces.BeanValidator";
Modified:
trunk/ui/validator/ui/src/main/java/org/richfaces/validator/FacesServiceBase.java
===================================================================
---
trunk/ui/validator/ui/src/main/java/org/richfaces/validator/FacesServiceBase.java 2011-03-07
17:31:10 UTC (rev 22076)
+++
trunk/ui/validator/ui/src/main/java/org/richfaces/validator/FacesServiceBase.java 2011-03-07
20:14:44 UTC (rev 22077)
@@ -7,6 +7,8 @@
import java.lang.reflect.InvocationTargetException;
import javax.faces.application.FacesMessage;
+import javax.faces.component.EditableValueHolder;
+import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import com.google.common.collect.ImmutableSet;
@@ -50,11 +52,23 @@
*
* @param context
* @param component
+ * @param input TODO
* @return
*/
- public FacesMessage getMessage(FacesContext context, T component) {
+ public FacesMessage getMessage(FacesContext context, T component, EditableValueHolder
input) {
String messageId = getMessageId(component);
return MessageFactory.createMessage(context, messageId);
}
+
+ protected void setLabelParameter(EditableValueHolder input, FacesValidatorDescriptor
descriptor) {
+ if (input instanceof UIComponent) {
+ UIComponent component = (UIComponent) input;
+ Object label = component.getAttributes().get("label");
+ if(null!=label){
+ descriptor.addParameter("label", label);
+ }
+ }
+ }
+
}
\ No newline at end of file
Modified:
trunk/ui/validator/ui/src/main/java/org/richfaces/validator/FacesValidatorServiceImpl.java
===================================================================
---
trunk/ui/validator/ui/src/main/java/org/richfaces/validator/FacesValidatorServiceImpl.java 2011-03-07
17:31:10 UTC (rev 22076)
+++
trunk/ui/validator/ui/src/main/java/org/richfaces/validator/FacesValidatorServiceImpl.java 2011-03-07
20:14:44 UTC (rev 22077)
@@ -4,6 +4,7 @@
package org.richfaces.validator;
import javax.faces.application.FacesMessage;
+import javax.faces.component.EditableValueHolder;
import javax.faces.component.UIInput;
import javax.faces.context.FacesContext;
import javax.faces.validator.DoubleRangeValidator;
@@ -19,15 +20,20 @@
*/
public class FacesValidatorServiceImpl extends FacesServiceBase<Validator>
implements FacesValidatorService {
+ private static final String PATTERN = "pattern";
+ private static final String MINIMUM = "min";
+ private static final String MAXIMUM = "max";
+
/*
* (non-Javadoc)
*
* @see
org.richfaces.validator.FacesValidatorService#getValidatorDescription(javax.faces.context.FacesContext,
* javax.faces.validator.Validator)
*/
- public ValidatorDescriptor getValidatorDescription(FacesContext context, Validator
validator) {
- FacesMessage message = getMessage(context, validator);
+ public ValidatorDescriptor getValidatorDescription(FacesContext context,
EditableValueHolder input, Validator validator) {
+ FacesMessage message = getMessage(context, validator, input);
FacesValidatorDescriptor descriptor = new
FacesValidatorDescriptor(validator.getClass(), message);
+ setLabelParameter(input, descriptor);
fillParameters(descriptor, validator);
descriptor.makeImmutable();
return descriptor;
@@ -39,7 +45,7 @@
String messageId;
if (component instanceof DoubleRangeValidator) {
DoubleRangeValidator validator = (DoubleRangeValidator) component;
- if(validator.getMaximum() > Double.MIN_VALUE){
+ if(validator.getMaximum() < Double.MAX_VALUE){
if(validator.getMinimum()> Double.MIN_VALUE){
messageId = DoubleRangeValidator.NOT_IN_RANGE_MESSAGE_ID;
} else {
@@ -65,13 +71,13 @@
}
} else if (component instanceof LongRangeValidator) {
LongRangeValidator validator = (LongRangeValidator) component;
- if(validator.getMaximum() >0){
- if(validator.getMinimum()>0){
+ if(validator.getMaximum() !=0){
+ if(validator.getMinimum()!=0){
messageId = DoubleRangeValidator.NOT_IN_RANGE_MESSAGE_ID;
} else {
messageId = LongRangeValidator.MAXIMUM_MESSAGE_ID;
}
- } else if( validator.getMinimum()>0){
+ } else if( validator.getMinimum()!=0){
messageId = LongRangeValidator.MINIMUM_MESSAGE_ID;
} else {
messageId = DoubleRangeValidator.NOT_IN_RANGE_MESSAGE_ID;// What to use
for that case ( no min/max set, validator always pass ).
@@ -86,4 +92,40 @@
return messageId;
}
+ @Override
+ protected void fillParameters(BaseFacesObjectDescriptor<Validator> descriptor,
Validator component) {
+ if (component instanceof DoubleRangeValidator) {
+ DoubleRangeValidator validator = (DoubleRangeValidator) component;
+ if(validator.getMaximum() < Double.MAX_VALUE){
+ descriptor.addParameter(MAXIMUM, validator.getMaximum());
+ }
+ if( validator.getMinimum()>Double.MIN_VALUE){
+ descriptor.addParameter(MINIMUM, validator.getMinimum());
+ }
+ } else if (component instanceof LengthValidator) {
+ LengthValidator validator = (LengthValidator) component;
+ if(validator.getMaximum() >0){
+ descriptor.addParameter(MAXIMUM, validator.getMaximum());
+ }
+ if( validator.getMinimum()>0){
+ descriptor.addParameter(MINIMUM, validator.getMinimum());
+ }
+ } else if (component instanceof LongRangeValidator) {
+ LongRangeValidator validator = (LongRangeValidator) component;
+ if(validator.getMaximum() !=0){
+ descriptor.addParameter(MAXIMUM, validator.getMaximum());
+ }
+ if( validator.getMinimum()!=0){
+ descriptor.addParameter(MINIMUM, validator.getMinimum());
+ }
+ } else if (component instanceof RegexValidator) {
+ RegexValidator validator = (RegexValidator) component;
+ descriptor.addParameter(PATTERN, validator.getPattern());
+ } else if (component instanceof RequiredValidator) {
+ // do nothing.
+ } else {
+ super.fillParameters(descriptor, component);
+ }
+
+ }
}
Copied:
trunk/ui/validator/ui/src/main/java/org/richfaces/view/facelets/html/GraphValidatorHandler.java
(from rev 22076,
branches/4.0.X/ui/validator/ui/src/main/java/org/richfaces/view/facelets/html/GraphValidatorHandler.java)
===================================================================
---
trunk/ui/validator/ui/src/main/java/org/richfaces/view/facelets/html/GraphValidatorHandler.java
(rev 0)
+++
trunk/ui/validator/ui/src/main/java/org/richfaces/view/facelets/html/GraphValidatorHandler.java 2011-03-07
20:14:44 UTC (rev 22077)
@@ -0,0 +1,162 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2011, Red Hat, Inc. and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.richfaces.view.facelets.html;
+
+import java.io.IOException;
+import java.util.Iterator;
+
+import javax.el.ELException;
+import javax.faces.FacesException;
+import javax.faces.component.EditableValueHolder;
+import javax.faces.component.StateHolder;
+import javax.faces.component.UIComponent;
+import javax.faces.context.FacesContext;
+import javax.faces.event.AbortProcessingException;
+import javax.faces.event.ComponentSystemEvent;
+import javax.faces.event.ComponentSystemEventListener;
+import javax.faces.event.PostAddToViewEvent;
+import javax.faces.validator.BeanValidator;
+import javax.faces.validator.Validator;
+import javax.faces.view.facelets.ComponentConfig;
+import javax.faces.view.facelets.ComponentHandler;
+import javax.faces.view.facelets.FaceletContext;
+
+import org.richfaces.component.AbstractGraphValidator;
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+public class GraphValidatorHandler extends ComponentHandler {
+
+ private static final String BUILT_IN_BEAN_VALIDATOR_ATTRIBUTE_NAME =
GraphValidatorHandler.class.getName()
+ + ":BUILT_IN_BEAN_VALIDATOR_ATTRIBUTE_NAME";
+
+ private class FacesBeanValidatorAddListener implements ComponentSystemEventListener,
StateHolder {
+
+ public void processEvent(ComponentSystemEvent event) throws
AbortProcessingException {
+ FacesContext context = FacesContext.getCurrentInstance();
+ Validator childrenValidator = createChildrenValidator(context,
event.getComponent());
+ setupValidators(context, event.getComponent(), childrenValidator);
+ }
+
+ public Object saveState(FacesContext context) {
+ throw new UnsupportedOperationException();
+ }
+
+ public void restoreState(FacesContext context, Object state) {
+ throw new UnsupportedOperationException();
+ }
+
+ public boolean isTransient() {
+ return true;
+ }
+
+ public void setTransient(boolean newTransientValue) {
+ throw new UnsupportedOperationException();
+ }
+ }
+
+ public GraphValidatorHandler(ComponentConfig config) {
+ super(config);
+ }
+
+ private Validator getBuiltInBeanValidator(FacesContext context) {
+ Validator result = (Validator)
context.getAttributes().get(BUILT_IN_BEAN_VALIDATOR_ATTRIBUTE_NAME);
+
+ if (result == null) {
+ result =
context.getApplication().createValidator(BeanValidator.VALIDATOR_ID);
+ context.getAttributes().put(BUILT_IN_BEAN_VALIDATOR_ATTRIBUTE_NAME, result);
+ }
+
+ return result;
+ }
+
+ private void setupValidators(FacesContext context, UIComponent component, Validator
validator) {
+ if (component.getChildCount() == 0 && component.getFacetCount() == 0) {
+ return;
+ }
+
+ Iterator<UIComponent> facetsAndChildren =
component.getFacetsAndChildren();
+ while (facetsAndChildren.hasNext()) {
+ UIComponent child = facetsAndChildren.next();
+ if (child instanceof EditableValueHolder) {
+ EditableValueHolder input = (EditableValueHolder) child;
+ setupValidator(context, input, validator);
+ }
+
+ if (!(child instanceof AbstractGraphValidator)) {
+ //don't setup validators for nested GVs
+ setupValidators(context, child, validator);
+ }
+
+ }
+ }
+
+ /**
+ * @param context TODO
+ * @param input
+ */
+ private void setupValidator(FacesContext context, EditableValueHolder input,
Validator beanValidator) {
+ boolean addBeanValidator = true;
+ Class<?> validatorToRemoveClass =
getBuiltInBeanValidator(context).getClass();
+ Validator validatorToRemove = null;
+
+ Validator[] validators = input.getValidators();
+ for (int i = 0; i < validators.length; i++) {
+ Validator nextValidator = validators[i];
+ if (nextValidator.getClass().equals(beanValidator.getClass())) {
+ addBeanValidator = false;
+ continue;
+ }
+
+ if (nextValidator.getClass().equals(validatorToRemoveClass)) {
+ validatorToRemove = nextValidator;
+ }
+ }
+
+ if (validatorToRemove != null) {
+ input.removeValidator(validatorToRemove);
+ }
+
+ if (addBeanValidator) {
+ input.addValidator(beanValidator);
+ }
+ }
+
+ private Validator createChildrenValidator(FacesContext context, UIComponent c) {
+ AbstractGraphValidator graphValidator = (AbstractGraphValidator) c;
+
+ return graphValidator.createChildrenValidator(context);
+ }
+
+ @Override
+ public void applyNextHandler(FaceletContext ctx, UIComponent c) throws IOException,
FacesException, ELException {
+ super.applyNextHandler(ctx, c);
+
+ if (c.isInView()) {
+ setupValidators(ctx.getFacesContext(), c,
createChildrenValidator(ctx.getFacesContext(), c));
+ } else {
+ c.subscribeToEvent(PostAddToViewEvent.class, new
FacesBeanValidatorAddListener());
+ }
+ }
+}
Modified: trunk/ui/validator/ui/src/main/resources/META-INF/csv.xml
===================================================================
--- trunk/ui/validator/ui/src/main/resources/META-INF/csv.xml 2011-03-07 17:31:10 UTC (rev
22076)
+++ trunk/ui/validator/ui/src/main/resources/META-INF/csv.xml 2011-03-07 20:14:44 UTC (rev
22077)
@@ -176,4 +176,20 @@
</resource>
<function>RichFaces.csv.validateMax</function>
</component>
+ <component>
+ <type>javax.validation.constraints.AssertTrue</type>
+ <resource>
+ <name>csv.reslib</name>
+ <library>org.richfaces</library>
+ </resource>
+ <function>RichFaces.csv.validateTrue</function>
+ </component>
+ <component>
+ <type>javax.validation.constraints.AssertFalse</type>
+ <resource>
+ <name>csv.reslib</name>
+ <library>org.richfaces</library>
+ </resource>
+ <function>RichFaces.csv.validateFalse</function>
+ </component>
</scripts>
\ No newline at end of file
Modified:
trunk/ui/validator/ui/src/main/resources/META-INF/resources/org.richfaces/richfaces-csv.js
===================================================================
---
trunk/ui/validator/ui/src/main/resources/META-INF/resources/org.richfaces/richfaces-csv.js 2011-03-07
17:31:10 UTC (rev 22076)
+++
trunk/ui/validator/ui/src/main/resources/META-INF/resources/org.richfaces/richfaces-csv.js 2011-03-07
20:14:44 UTC (rev 22077)
@@ -3,12 +3,10 @@
rf.csv = rf.csv || {};
var _messages = {};
- var _validators = {};
- var _converters = {};
var RE_MESSAGE_PATTERN = /\'?\{(\d+)\}\'?/g;
- var __interpolateMessage = function (message, values) {
+ var interpolateMessage = function (message, values) {
if (message) {
var msgObject =
message.replace(RE_MESSAGE_PATTERN,"\n$1\n").split("\n");
var value;
@@ -21,21 +19,115 @@
return "";
}
}
-
- var __getValue = function(id) {
+ var _value_query = function(control){
+ if(null !== control.value && undefined != control.value){
+ return control.value;
+ } else {
+ return "";
+ }
+ };
+
+ var _check_query = function(control){
+ if( control.checked ) {
+ return true;
+ } else {
+ return false;
+ }
+ };
+
+ var _addOption = function(value,option){
+ if ( option.selected ){
+ return value[value.length]=option.value;
+ }
+
+ };
+
+ var valueExtractors = {
+ hidden : function(control){
+ return _value_query(control);
+ },
+
+ text : function(control){
+ return _value_query(control);
+ },
+
+ textarea : function(control){
+ return _value_query(control);
+ },
+
+ 'select-one' : function(control){
+ if (control.selectedIndex != -1) {
+ return _value_query(control);
+ }
+ },
+
+ password : function(control){
+ return _value_query(control);
+ },
+
+ file : function(control){
+ return _value_query(control);
+ },
+
+ radio : function(control){
+ return _check_query(control);
+ },
+
+ checkbox : function(control){
+ return _check_query(control);
+ },
+
+
+ 'select-multiple' : function(control){
+ var cname = control.name;
+ var childs = control.childNodes;
+ var value = [];
+ for( var i=0 ;i< childs.length;i++ ){
+ var child=childs[i];
+ if( child.tagName === 'OPTGROUP' ){
+ var options = child.childNodes;
+ for(var j=0; j < options.length; j++){
+ value = _addOption(value, options[j]);
+ }
+ } else {
+ value =_addOption(value, child);
+ }
+ }
+ return value;
+ },
+
+ // command inputs
+
+
+ // same as link, but have additional field - control, for input
+ // submit.
+ input : function(control){
+ return _value_query(control);
+ }
+ };
+
+ var getValue = function(id) {
var value;
var element = rf.getDomElement(id);
- if (element.value) {
+ if (valueExtractors[element.type]) {
+ value = valueExtractors[element.type](element);
+ } else if(undefined !== element.value ){
value = element.value;
} else {
var component = rf.$(element);
// TODO: add getValue to baseComponent and change jsdocs
- value = component && typeof component["getValue"] ==
"function" ? component.getValue() : "";
+ value = component && typeof component["getValue"] ===
"function" ? component.getValue() : "";
}
return value;
}
+ var getLabel = function(component,id){
+ if(component.p){
+ return component.p.label || id;
+ }
+ return id;
+ }
$.extend(rf.csv, {
RE_DIGITS: /^-?\d+$/,
@@ -46,10 +138,10 @@
},
getMessage: function(customMessage, messageId, values) {
var message = customMessage ? customMessage : _messages[messageId] ||
{detail:"",summary:"",severity:0};
- return
{detail:__interpolateMessage(message.detail,values),summary:__interpolateMessage(message.summary,values),severity:message.severity};
+ return
{detail:interpolateMessage(message.detail,values),summary:interpolateMessage(message.summary,values),severity:message.severity};
},
interpolateMessage: function(message,values){
- return
{detail:__interpolateMessage(message.detail,values),summary:__interpolateMessage(message.summary,values),severity:message.severity};
+ return
{detail:interpolateMessage(message.detail,values),summary:interpolateMessage(message.summary,values),severity:message.severity};
},
sendMessage: function (componentId, message) {
rf.Event.fire(window.document, rf.Event.MESSAGE_EVENT_TYPE,
{'sourceId':componentId, 'message':message});
@@ -58,14 +150,15 @@
rf.Event.fire(window.document, rf.Event.MESSAGE_EVENT_TYPE,
{'sourceId':componentId });
},
validate: function (event, id, element, params) {
- var value = __getValue(element || id);
+ var value = getValue(element || id);
var convertedValue;
var converter = params.c;
rf.csv.clearMessage(id);
if (converter) {
+ var label=getLabel(converter,id);
try {
if (converter.f)
- convertedValue = converter.f(value,id,converter.p,converter.m);
+ convertedValue = converter.f(value,id,getLabel(converter,id),converter.m);
} catch (e){
e.severity=2;
rf.csv.sendMessage(id, e);
@@ -74,30 +167,33 @@
} else {
convertedValue = value;
}
+ var result = true
var validators = params.v;
if (validators) {
- var validatorFunction;
- try {
+ var validatorFunction,validator;
for (i=0;i<validators.length;i++) {
- validatorFunction = validators[i].f;
- if (validatorFunction) {
- validatorFunction(convertedValue,id, validators[i].p,validators[i].m);
+ try {
+ validator=validators[i];
+ validatorFunction = validator.f;
+ if (validatorFunction) {
+ validatorFunction(convertedValue,getLabel(validator,id),
validator.p,validator.m);
+ }
+ } catch (e) {
+ e.severity=2;
+ rf.csv.sendMessage(id, e);
+ result = false;
}
}
- } catch (e) {
- e.severity=2;
- rf.csv.sendMessage(id, e);
- return false;
- }
}
- if(!params.da && params.a){
+ if(!result && !params.da && params.a){
params.a.call(element,event,id);
}
- return true;
+ return result;
},
});
- /* convert all natural number formats
+ /*
+ * convert all natural number formats
*
*/
var _convertNatural = function(value,label,msg,min,max,sample){
@@ -121,10 +217,15 @@
*/
$.extend(rf.csv, {
"convertBoolean": function (value,label,params,msg) {
- var result; value = $.trim(value).toLowerCase();
- result = value=='true' ? true : value.length<1 ? null : false;
-
- return result;
+ if( typeof value === "string"){
+ var lcvalue = $.trim(value).toLowerCase();
+ if(lcvalue === 'on' || lcvalue==='true' || lcvalue===
'yes'){
+ return true;
+ }
+ } else if(true === value){
+ return true;
+ }
+ return false;
},
"convertDate": function (value,label,params,msg) {
var result; value = $.trim(value);
@@ -164,14 +265,14 @@
});
var validateRange = function(value,label,params,msg) {
- var isMinSet = typeof params.minimum === "number" ;//&&
params.minimum >0;
- var isMaxSet = typeof params.maximum === "number" ;//&&
params.maximum >0;
+ var isMinSet = typeof params.min === "number" ;// && params.min
>0;
+ var isMaxSet = typeof params.max === "number" ;// && params.max
>0;
- if (isMaxSet && value > params.maximum) {
- throw
rf.csv.interpolateMessage(msg,isMinSet?[params.minimum,params.maximum,label]:[params.maximum,label]);
+ if (isMaxSet && value > params.max) {
+ throw
rf.csv.interpolateMessage(msg,isMinSet?[params.min,params.max,label]:[params.max,label]);
}
- if (isMinSet && value < params.minimum) {
- throw
rf.csv.interpolateMessage(msg,isMaxSet?[params.minimum,params.maximum,label]:[params.minimum,label]);
+ if (isMinSet && value < params.min) {
+ throw
rf.csv.interpolateMessage(msg,isMaxSet?[params.min,params.max,label]:[params.min,label]);
}
};
@@ -197,7 +298,7 @@
$.extend(rf.csv, {
"validateLongRange": function (value,label,params,msg) {
var type = typeof value;
- if (type != "number") {
+ if (type !== "number") {
if (type != "string") {
throw rf.csv.getMessage(msg, 'LONG_RANGE_VALIDATOR_TYPE', [componentId,
""]);
} else {
@@ -212,8 +313,8 @@
},
"validateDoubleRange": function (value,label,params,msg) {
var type = typeof value;
- if (type != "number") {
- if (type != "string") {
+ if (type !== "number") {
+ if (type !== "string") {
throw rf.csv.getMessage(msg, 'DOUBLE_RANGE_VALIDATOR_TYPE', [componentId,
""]);
} else {
value = $.trim(value);
@@ -231,7 +332,7 @@
},
"validateSize": function (value,label,params,msg) {
var length = value?value.length:0;
- validateRange(length,label,{maximum:params.max,minimum:params.min},msg);
+ validateRange(length,label,params,msg);
},
"validateRegex": function (value,label,params,msg) {
validateRegex(value,label,params.pattern,msg);
@@ -244,6 +345,16 @@
throw rf.csv.interpolateMessage(msg, [label]);
}
},
+ "validateTrue": function (value,label,params,msg) {
+ if ( value !== true ) {
+ throw msg;
+ }
+ },
+ "validateFalse": function (value,label,params,msg) {
+ if (value !== false) {
+ throw msg;
+ }
+ },
"validateMax": function (value,label,params,msg) {
if (value > params.value ) {
throw msg;
Modified:
trunk/ui/validator/ui/src/test/java/org/richfaces/component/behavior/BehaviorGetConverterTest.java
===================================================================
---
trunk/ui/validator/ui/src/test/java/org/richfaces/component/behavior/BehaviorGetConverterTest.java 2011-03-07
17:31:10 UTC (rev 22076)
+++
trunk/ui/validator/ui/src/test/java/org/richfaces/component/behavior/BehaviorGetConverterTest.java 2011-03-07
20:14:44 UTC (rev 22077)
@@ -45,7 +45,7 @@
public void setupService() {
expect(factory.getInstance(FacesConverterService.class)).andStubReturn(converterService);
converterCapture = new Capture<Converter>();
-
expect(converterService.getConverterDescription(eq(environment.getFacesContext()),
capture(converterCapture)))
+
expect(converterService.getConverterDescription(same(environment.getFacesContext()),
same(input), capture(converterCapture)))
.andStubReturn(descriptor);
ServiceTracker.setFactory(factory);
}
Modified:
trunk/ui/validator/ui/src/test/java/org/richfaces/component/behavior/BehaviorGetValidatorTest.java
===================================================================
---
trunk/ui/validator/ui/src/test/java/org/richfaces/component/behavior/BehaviorGetValidatorTest.java 2011-03-07
17:31:10 UTC (rev 22076)
+++
trunk/ui/validator/ui/src/test/java/org/richfaces/component/behavior/BehaviorGetValidatorTest.java 2011-03-07
20:14:44 UTC (rev 22077)
@@ -107,7 +107,7 @@
ValidatorDescriptor validatorDescriptor =
environment.createMock(ValidatorDescriptor.class);
expect((Class)
validatorDescriptor.getImplementationClass()).andStubReturn(validator.getClass());
expect(validatorDescriptor.getMessage()).andStubReturn(VALIDATION_ERROR);
-
expect(facesValidatorService.getValidatorDescription(environment.getFacesContext(),
validator))
+
expect(facesValidatorService.getValidatorDescription(environment.getFacesContext(), input,
validator))
.andStubReturn(validatorDescriptor);
}
}
Modified: trunk/ui/validator/ui/src/test/java/org/richfaces/el/ELTestBase.java
===================================================================
--- trunk/ui/validator/ui/src/test/java/org/richfaces/el/ELTestBase.java 2011-03-07
17:31:10 UTC (rev 22076)
+++ trunk/ui/validator/ui/src/test/java/org/richfaces/el/ELTestBase.java 2011-03-07
20:14:44 UTC (rev 22077)
@@ -15,6 +15,7 @@
import javax.el.MapELResolver;
import javax.el.ValueExpression;
import javax.el.VariableMapper;
+import javax.faces.context.FacesContext;
import org.jboss.el.ExpressionFactoryImpl;
import org.junit.After;
@@ -89,6 +90,10 @@
class DummyELContext extends ELContext {
+ public DummyELContext() {
+ putContext(FacesContext.class, FacesContext.getCurrentInstance());
+ }
+
@Override
public ELResolver getELResolver() {
return elResolver;
Modified: trunk/ui/validator/ui/src/test/java/org/richfaces/el/TestCaptureEL.java
===================================================================
--- trunk/ui/validator/ui/src/test/java/org/richfaces/el/TestCaptureEL.java 2011-03-07
17:31:10 UTC (rev 22076)
+++ trunk/ui/validator/ui/src/test/java/org/richfaces/el/TestCaptureEL.java 2011-03-07
20:14:44 UTC (rev 22077)
@@ -1,16 +1,47 @@
package org.richfaces.el;
-import static org.junit.Assert.*;
+import static org.easymock.EasyMock.expect;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertSame;
import javax.el.ValueExpression;
+import org.jboss.test.faces.mock.Environment;
+import org.jboss.test.faces.mock.Environment.Feature;
+import org.jboss.test.faces.mock.FacesMock;
+import org.jboss.test.faces.mock.Mock;
+import org.jboss.test.faces.mock.MockFacesEnvironment;
import org.jboss.test.faces.mock.MockTestRunner;
+import org.junit.After;
+import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
+import com.google.common.collect.Maps;
+
@RunWith(MockTestRunner.class)
public class TestCaptureEL extends ELTestBase {
+ @Mock
+ @Environment(Feature.EXTERNAL_CONTEXT)
+ private MockFacesEnvironment facesEnvironment;
+
+
+ @Before
+ public void setUpEnvironment() throws Exception {
+
expect(facesEnvironment.getExternalContext().getRequestMap()).andStubReturn(Maps.<String,
Object>newHashMap());
+
expect(facesEnvironment.getFacesContext().getAttributes()).andStubReturn(Maps.<Object,
Object>newHashMap());
+ FacesMock.replay(facesEnvironment);
+ }
+
+ @After
+ public void tearDownEnvironment() throws Exception {
+ FacesMock.verify(facesEnvironment);
+ facesEnvironment.release();
+ }
+
@Test
public void testDummyResolverString() throws Exception {
ValueExpression expression = parse("#{bean.string}");
Modified:
trunk/ui/validator/ui/src/test/java/org/richfaces/el/ValueExpressionAnalayserTest.java
===================================================================
---
trunk/ui/validator/ui/src/test/java/org/richfaces/el/ValueExpressionAnalayserTest.java 2011-03-07
17:31:10 UTC (rev 22076)
+++
trunk/ui/validator/ui/src/test/java/org/richfaces/el/ValueExpressionAnalayserTest.java 2011-03-07
20:14:44 UTC (rev 22077)
@@ -1,15 +1,18 @@
package org.richfaces.el;
-import static org.easymock.EasyMock.*;
-import static org.junit.Assert.*;
+import static org.easymock.EasyMock.expect;
+import static org.junit.Assert.assertEquals;
import javax.el.ELException;
import javax.el.ValueExpression;
import javax.faces.context.FacesContext;
+import org.jboss.test.faces.mock.Environment;
+import org.jboss.test.faces.mock.Environment.Feature;
import org.jboss.test.faces.mock.FacesMock;
import org.jboss.test.faces.mock.Mock;
+import org.jboss.test.faces.mock.MockFacesEnvironment;
import org.jboss.test.faces.mock.MockTestRunner;
import org.junit.After;
import org.junit.Before;
@@ -17,42 +20,48 @@
import org.junit.runner.RunWith;
import org.richfaces.el.model.Bean;
+import com.google.common.collect.Maps;
+
@RunWith(MockTestRunner.class)
public class ValueExpressionAnalayserTest extends ELTestBase {
-
private ValueExpressionAnalayser analayser;
@Mock
+ @Environment(Feature.EXTERNAL_CONTEXT)
+ private MockFacesEnvironment facesEnvironment;
+
private FacesContext facesContext;
-
+
@Before
public void setUpAnalayser() throws Exception {
analayser = new ValueExpressionAnalayserImpl();
+ facesContext = facesEnvironment.getFacesContext();
+
expect(facesEnvironment.getExternalContext().getRequestMap()).andStubReturn(Maps.<String,
Object>newHashMap());
}
@After
public void tearDownAnalayser() throws Exception {
+ facesContext = null;
analayser = null;
- facesContext.release();
+ facesEnvironment.release();
}
@Test
public void testGetDescriptionPositive() throws Exception {
ValueExpression expression = parse("#{bean.string}");
expect(facesContext.getELContext()).andReturn(elContext);
- FacesMock.replay(facesContext);
+ FacesMock.replay(facesEnvironment);
ValueDescriptor propertyDescriptor =
analayser.getPropertyDescriptor(facesContext, expression);
assertEquals(Bean.class, propertyDescriptor.getBeanType());
assertEquals("string", propertyDescriptor.getName());
- assertEquals(String.class,propertyDescriptor.getPropertyType());
- FacesMock.verify(facesContext);
+ FacesMock.verify(facesEnvironment);
}
@Test(expected=ELException.class)
public void testGetDescriptionNegative() throws Exception {
ValueExpression expression = parse("#{bean}");
expect(facesContext.getELContext()).andReturn(elContext);
- FacesMock.replay(facesContext);
+ FacesMock.replay(facesEnvironment);
ValueDescriptor propertyDescriptor =
analayser.getPropertyDescriptor(facesContext, expression);
}
}
Modified:
trunk/ui/validator/ui/src/test/java/org/richfaces/javascript/client/MockTestBase.java
===================================================================
---
trunk/ui/validator/ui/src/test/java/org/richfaces/javascript/client/MockTestBase.java 2011-03-07
17:31:10 UTC (rev 22076)
+++
trunk/ui/validator/ui/src/test/java/org/richfaces/javascript/client/MockTestBase.java 2011-03-07
20:14:44 UTC (rev 22077)
@@ -7,7 +7,7 @@
import java.util.Locale;
import java.util.Map;
-import javax.faces.component.UIComponent;
+import javax.faces.component.UIInput;
import javax.faces.component.UIViewRoot;
import org.jboss.test.faces.mock.MockFacesEnvironment;
@@ -32,7 +32,7 @@
protected final RunParameters criteria;
protected MockFacesEnvironment facesEnvironment;
- protected UIComponent component;
+ protected UIInput input;
public MockTestBase(RunParameters criteria) {
this.criteria = criteria;
@@ -42,7 +42,7 @@
@Before
public void setUp() {
this.facesEnvironment =
MockFacesEnvironment.createEnvironment().withApplication().resetToNice();
- component = facesEnvironment.createMock(UIComponent.class);
+ input = facesEnvironment.createMock(UIInput.class);
recordMocks();
facesEnvironment.replay();
}
@@ -51,8 +51,8 @@
UIViewRoot viewRoot = facesEnvironment.createMock(UIViewRoot.class);
expect(viewRoot.getLocale()).andStubReturn(Locale.ENGLISH);
expect(facesEnvironment.getFacesContext().getViewRoot()).andStubReturn(viewRoot);
- expect(component.getAttributes()).andStubReturn(Collections.EMPTY_MAP);
-
expect(component.getClientId(facesEnvironment.getFacesContext())).andStubReturn(TEST_COMPONENT_ID);
+ expect(input.getAttributes()).andStubReturn(Collections.EMPTY_MAP);
+
expect(input.getClientId(facesEnvironment.getFacesContext())).andStubReturn(TEST_COMPONENT_ID);
}
@After
Modified:
trunk/ui/validator/ui/src/test/java/org/richfaces/javascript/client/converter/BooleanConverterTest.java
===================================================================
---
trunk/ui/validator/ui/src/test/java/org/richfaces/javascript/client/converter/BooleanConverterTest.java 2011-03-07
17:31:10 UTC (rev 22076)
+++
trunk/ui/validator/ui/src/test/java/org/richfaces/javascript/client/converter/BooleanConverterTest.java 2011-03-07
20:14:44 UTC (rev 22077)
@@ -26,6 +26,6 @@
@Parameters
public static List<RunParameters[]> getRunParameterss() {
- return options(pass("true"), pass("ok"),
pass("123"),pass("0"),pass("1"));
+ return options(pass("true"), pass("ok"),
pass("123"),pass("0"),pass("1"),pass("no"));
}
}
Modified:
trunk/ui/validator/ui/src/test/java/org/richfaces/javascript/client/converter/ByteConverterTest.java
===================================================================
---
trunk/ui/validator/ui/src/test/java/org/richfaces/javascript/client/converter/ByteConverterTest.java 2011-03-07
17:31:10 UTC (rev 22076)
+++
trunk/ui/validator/ui/src/test/java/org/richfaces/javascript/client/converter/ByteConverterTest.java 2011-03-07
20:14:44 UTC (rev 22077)
@@ -5,7 +5,6 @@
import java.util.List;
-import javax.faces.convert.BooleanConverter;
import javax.faces.convert.ByteConverter;
import javax.faces.convert.Converter;
Modified:
trunk/ui/validator/ui/src/test/java/org/richfaces/javascript/client/converter/ConverterTestBase.java
===================================================================
---
trunk/ui/validator/ui/src/test/java/org/richfaces/javascript/client/converter/ConverterTestBase.java 2011-03-07
17:31:10 UTC (rev 22076)
+++
trunk/ui/validator/ui/src/test/java/org/richfaces/javascript/client/converter/ConverterTestBase.java 2011-03-07
20:14:44 UTC (rev 22077)
@@ -1,13 +1,10 @@
package org.richfaces.javascript.client.converter;
-import static junit.framework.Assert.assertEquals;
-import static junit.framework.Assert.assertTrue;
import static org.junit.Assert.*;
import javax.faces.application.FacesMessage;
import javax.faces.convert.Converter;
import javax.faces.convert.ConverterException;
-import javax.faces.validator.Validator;
import net.sourceforge.htmlunit.corejs.javascript.JavaScriptException;
import net.sourceforge.htmlunit.corejs.javascript.NativeObject;
@@ -33,7 +30,7 @@
Converter converter = createConverter();
try {
Object convertedValue =
- converter.getAsObject(facesEnvironment.getFacesContext(), component,
criteria.getValue().toString());
+ converter.getAsObject(facesEnvironment.getFacesContext(), input,
criteria.getValue().toString());
Object jsConvertedValue =
convertOnClient(converter);
if(null != convertedValue || null != jsConvertedValue){
@@ -66,7 +63,7 @@
private Object getErrorMessage(Converter converter) {
ConverterServiceImpl converterService = new ConverterServiceImpl();
- FacesMessage message =
converterService.getMessage(facesEnvironment.getFacesContext(), converter);
+ FacesMessage message =
converterService.getMessage(facesEnvironment.getFacesContext(), converter, input);
return new Message(message);
}
Modified:
trunk/ui/validator/ui/src/test/java/org/richfaces/javascript/client/converter/NumberConverterTest.java
===================================================================
---
trunk/ui/validator/ui/src/test/java/org/richfaces/javascript/client/converter/NumberConverterTest.java 2011-03-07
17:31:10 UTC (rev 22076)
+++
trunk/ui/validator/ui/src/test/java/org/richfaces/javascript/client/converter/NumberConverterTest.java 2011-03-07
20:14:44 UTC (rev 22077)
@@ -4,7 +4,6 @@
import java.util.List;
import java.util.Map;
-import javax.faces.convert.BooleanConverter;
import javax.faces.convert.NumberConverter;
import javax.faces.convert.Converter;
Modified:
trunk/ui/validator/ui/src/test/java/org/richfaces/javascript/client/converter/ShortConverterTest.java
===================================================================
---
trunk/ui/validator/ui/src/test/java/org/richfaces/javascript/client/converter/ShortConverterTest.java 2011-03-07
17:31:10 UTC (rev 22076)
+++
trunk/ui/validator/ui/src/test/java/org/richfaces/javascript/client/converter/ShortConverterTest.java 2011-03-07
20:14:44 UTC (rev 22077)
@@ -1,11 +1,8 @@
package org.richfaces.javascript.client.converter;
-import static junit.framework.Assert.assertEquals;
-import static junit.framework.Assert.assertTrue;
import java.util.List;
-import javax.faces.convert.BooleanConverter;
import javax.faces.convert.ShortConverter;
import javax.faces.convert.Converter;
Modified:
trunk/ui/validator/ui/src/test/java/org/richfaces/javascript/client/validator/DoubleRangeValidatorTest.java
===================================================================
---
trunk/ui/validator/ui/src/test/java/org/richfaces/javascript/client/validator/DoubleRangeValidatorTest.java 2011-03-07
17:31:10 UTC (rev 22076)
+++
trunk/ui/validator/ui/src/test/java/org/richfaces/javascript/client/validator/DoubleRangeValidatorTest.java 2011-03-07
20:14:44 UTC (rev 22077)
@@ -18,8 +18,8 @@
*/
public class DoubleRangeValidatorTest extends ValidatorTestBase {
- private static final String MINIMUM = "minimum";
- private static final String MAXIMUM = "maximum";
+ private static final String MINIMUM = "min";
+ private static final String MAXIMUM = "max";
/**
* @param criteria
*/
Modified:
trunk/ui/validator/ui/src/test/java/org/richfaces/javascript/client/validator/LengthValidatorTest.java
===================================================================
---
trunk/ui/validator/ui/src/test/java/org/richfaces/javascript/client/validator/LengthValidatorTest.java 2011-03-07
17:31:10 UTC (rev 22076)
+++
trunk/ui/validator/ui/src/test/java/org/richfaces/javascript/client/validator/LengthValidatorTest.java 2011-03-07
20:14:44 UTC (rev 22077)
@@ -18,8 +18,8 @@
*/
public class LengthValidatorTest extends ValidatorTestBase {
- private static final String MINIMUM = "minimum";
- private static final String MAXIMUM = "maximum";
+ private static final String MINIMUM = "min";
+ private static final String MAXIMUM = "max";
/**
* @param criteria
*/
Modified:
trunk/ui/validator/ui/src/test/java/org/richfaces/javascript/client/validator/LongRangeValidatorTest.java
===================================================================
---
trunk/ui/validator/ui/src/test/java/org/richfaces/javascript/client/validator/LongRangeValidatorTest.java 2011-03-07
17:31:10 UTC (rev 22076)
+++
trunk/ui/validator/ui/src/test/java/org/richfaces/javascript/client/validator/LongRangeValidatorTest.java 2011-03-07
20:14:44 UTC (rev 22077)
@@ -18,8 +18,8 @@
*/
public class LongRangeValidatorTest extends ValidatorTestBase {
- private static final String MINIMUM = "minimum";
- private static final String MAXIMUM = "maximum";
+ private static final String MINIMUM = "min";
+ private static final String MAXIMUM = "max";
/**
* @param criteria
*/
Modified:
trunk/ui/validator/ui/src/test/java/org/richfaces/javascript/client/validator/MaxValidatorTest.java
===================================================================
---
trunk/ui/validator/ui/src/test/java/org/richfaces/javascript/client/validator/MaxValidatorTest.java 2011-03-07
17:31:10 UTC (rev 22076)
+++
trunk/ui/validator/ui/src/test/java/org/richfaces/javascript/client/validator/MaxValidatorTest.java 2011-03-07
20:14:44 UTC (rev 22077)
@@ -4,10 +4,7 @@
package org.richfaces.javascript.client.validator;
import java.util.List;
-import java.util.Map;
-import javax.faces.validator.LengthValidator;
-import javax.faces.validator.Validator;
import javax.validation.constraints.Max;
import org.junit.runners.Parameterized.Parameters;
@@ -38,9 +35,8 @@
@Parameters
public static List<RunParameters[]> parameters() {
- return options(
-
pass(0,PROP,"number",MAXIMUM,2),pass(2,PROP,"number",MAXIMUM,2),pass(123,PROP,"number",MAXIMUM,2)
- );
+ return options(pass(0, PROP, "number", MAXIMUM, 2), pass(2, PROP,
"number", MAXIMUM, 2),
+ pass(123, PROP, "number", MAXIMUM, 2));
}
public static final class Bean {
Modified:
trunk/ui/validator/ui/src/test/java/org/richfaces/javascript/client/validator/ValidatorTestBase.java
===================================================================
---
trunk/ui/validator/ui/src/test/java/org/richfaces/javascript/client/validator/ValidatorTestBase.java 2011-03-07
17:31:10 UTC (rev 22076)
+++
trunk/ui/validator/ui/src/test/java/org/richfaces/javascript/client/validator/ValidatorTestBase.java 2011-03-07
20:14:44 UTC (rev 22077)
@@ -49,7 +49,7 @@
public void testValidator() throws Exception {
Validator validator = createValidator();
try {
- validator.validate(facesEnvironment.getFacesContext(), component,
criteria.getValue());
+ validator.validate(facesEnvironment.getFacesContext(), input,
criteria.getValue());
validateOnClient(validator);
} catch (ValidatorException e) {
// client-side script has to throw exception too.
@@ -80,7 +80,7 @@
private Object getErrorMessage(Validator validator) {
FacesValidatorServiceImpl validatorService = new FacesValidatorServiceImpl();
- FacesMessage message =
validatorService.getMessage(facesEnvironment.getFacesContext(), validator);
+ FacesMessage message =
validatorService.getMessage(facesEnvironment.getFacesContext(), validator, input);
return new Message(message);
}
Modified:
trunk/ui/validator/ui/src/test/java/org/richfaces/validator/FacesConverterServiceTest.java
===================================================================
---
trunk/ui/validator/ui/src/test/java/org/richfaces/validator/FacesConverterServiceTest.java 2011-03-07
17:31:10 UTC (rev 22076)
+++
trunk/ui/validator/ui/src/test/java/org/richfaces/validator/FacesConverterServiceTest.java 2011-03-07
20:14:44 UTC (rev 22077)
@@ -70,7 +70,7 @@
public void getConverterClass() throws Exception {
converter = new BooleanConverter();
controller.replay();
- ConverterDescriptor converterDescription =
serviceImpl.getConverterDescription(environment.getFacesContext(), converter);
+ ConverterDescriptor converterDescription =
serviceImpl.getConverterDescription(environment.getFacesContext(), input, converter);
assertEquals(converter.getClass(),
converterDescription.getImplementationClass());
}
@@ -85,7 +85,7 @@
facesMessage = e.getFacesMessage();
}
assertNotNull(facesMessage);
- ConverterDescriptor converterDescription =
serviceImpl.getConverterDescription(environment.getFacesContext(), converter);
+ ConverterDescriptor converterDescription =
serviceImpl.getConverterDescription(environment.getFacesContext(), input, converter);
String summary = converterDescription.getMessage().getSummary();
summary = summary.replace("{2}", "foo");
summary = summary.replace("'{0}'", "abc");
@@ -102,7 +102,7 @@
converter.setType("both");
converter.setTimeZone(TimeZone.getTimeZone("EST"));
controller.replay();
- ConverterDescriptor converterDescription =
serviceImpl.getConverterDescription(environment.getFacesContext(), converter);
+ ConverterDescriptor converterDescription =
serviceImpl.getConverterDescription(environment.getFacesContext(), input, converter);
Map<String, ? extends Object> additionalParameters =
converterDescription.getAdditionalParameters();
assertEquals("short",
additionalParameters.get("dateStyle"));
assertEquals("MM/DD/YYYY",
additionalParameters.get("pattern"));
Modified:
trunk/ui/validator/ui/src/test/java/org/richfaces/validator/FacesValidatorServiceTest.java
===================================================================
---
trunk/ui/validator/ui/src/test/java/org/richfaces/validator/FacesValidatorServiceTest.java 2011-03-07
17:31:10 UTC (rev 22076)
+++
trunk/ui/validator/ui/src/test/java/org/richfaces/validator/FacesValidatorServiceTest.java 2011-03-07
20:14:44 UTC (rev 22077)
@@ -65,7 +65,7 @@
public void getConverterClass() throws Exception {
validator = new LengthValidator();
controller.replay();
- ValidatorDescriptor validatorDescription =
serviceImpl.getValidatorDescription(environment.getFacesContext(), validator);
+ ValidatorDescriptor validatorDescription =
serviceImpl.getValidatorDescription(environment.getFacesContext(), input, validator);
assertEquals(validator.getClass(),
validatorDescription.getImplementationClass());
}
@@ -80,7 +80,7 @@
facesMessage = e.getFacesMessage();
}
assertNotNull(facesMessage);
- ValidatorDescriptor validatorDescription =
serviceImpl.getValidatorDescription(environment.getFacesContext(), validator);
+ ValidatorDescriptor validatorDescription =
serviceImpl.getValidatorDescription(environment.getFacesContext(), input, validator);
String summary = validatorDescription.getMessage().getSummary();
summary = summary.replace("{0}", "foo");
assertEquals(facesMessage.getSummary(), summary);