Author: alexsmirnov
Date: 2011-03-04 17:55:38 -0500 (Fri, 04 Mar 2011)
New Revision: 22066
Added:
branches/4.0.X/examples/validator-demo/src/main/java/org/richfaces/example/PasswordValidationBean.java
branches/4.0.X/examples/validator-demo/src/main/webapp/examples/passwordValidation.xhtml
branches/4.0.X/examples/validator-demo/src/main/webapp/resources/org.richfaces.showcase/
branches/4.0.X/examples/validator-demo/src/main/webapp/resources/org.richfaces.showcase/test.xhtml
branches/4.0.X/examples/validator-demo/src/main/webapp/resources/org.richfaces.showcase/test1.xhtml
branches/4.0.X/examples/validator-demo/src/main/webapp/richfaces/
branches/4.0.X/examples/validator-demo/src/main/webapp/richfaces/graphValidator/
branches/4.0.X/examples/validator-demo/src/main/webapp/richfaces/graphValidator/samples/
Removed:
branches/4.0.X/ui/validator/ui/src/main/java/org/richfaces/validator/ClonedObjectResolver.java
Modified:
branches/4.0.X/examples/template/src/main/webapp/layout/pagesList.xhtml
branches/4.0.X/ui/validator/api/src/main/java/org/richfaces/el/ValueDescriptor.java
branches/4.0.X/ui/validator/api/src/main/java/org/richfaces/el/ValueExpressionAnalayser.java
branches/4.0.X/ui/validator/api/src/main/java/org/richfaces/validator/GraphValidatorState.java
branches/4.0.X/ui/validator/ui/src/main/java/org/richfaces/component/AbstractGraphValidator.java
branches/4.0.X/ui/validator/ui/src/main/java/org/richfaces/el/CapturingELContext.java
branches/4.0.X/ui/validator/ui/src/main/java/org/richfaces/el/ValueExpressionAnalayserImpl.java
branches/4.0.X/ui/validator/ui/src/main/java/org/richfaces/validator/BeanValidatorServiceImpl.java
branches/4.0.X/ui/validator/ui/src/test/java/org/richfaces/el/ELTestBase.java
branches/4.0.X/ui/validator/ui/src/test/java/org/richfaces/el/TestCaptureEL.java
branches/4.0.X/ui/validator/ui/src/test/java/org/richfaces/el/ValueExpressionAnalayserTest.java
Log:
Nick's code reviewed.
RESOLVED - issue RF-10610: BeanValidator ignores
javax.faces.el.CompositeComponentExpressionHolder
https://issues.jboss.org/browse/RF-10610
https://issues.jboss.org/browse/RF-10456
Modified: branches/4.0.X/examples/template/src/main/webapp/layout/pagesList.xhtml
===================================================================
--- branches/4.0.X/examples/template/src/main/webapp/layout/pagesList.xhtml 2011-03-04
19:24:40 UTC (rev 22065)
+++ branches/4.0.X/examples/template/src/main/webapp/layout/pagesList.xhtml 2011-03-04
22:55:38 UTC (rev 22066)
@@ -8,7 +8,7 @@
<h:form>
<h:dataTable value="#{pages.xhtmlPages}" var="page">
<h:column>
- <h:outputLink value="#{page.url}"
>#{page.title}</h:outputLink>
+ <h:outputLink value="#{page.url}" ><h:outputText
value="#{page.title}" escape="false"/></h:outputLink>
</h:column>
</h:dataTable>
</h:form>
Added:
branches/4.0.X/examples/validator-demo/src/main/java/org/richfaces/example/PasswordValidationBean.java
===================================================================
---
branches/4.0.X/examples/validator-demo/src/main/java/org/richfaces/example/PasswordValidationBean.java
(rev 0)
+++
branches/4.0.X/examples/validator-demo/src/main/java/org/richfaces/example/PasswordValidationBean.java 2011-03-04
22:55:38 UTC (rev 22066)
@@ -0,0 +1,49 @@
+package org.richfaces.example;
+
+import java.io.Serializable;
+
+import javax.faces.application.FacesMessage;
+import javax.faces.bean.ManagedBean;
+import javax.faces.bean.SessionScoped;
+import javax.faces.context.FacesContext;
+import javax.validation.constraints.AssertTrue;
+import javax.validation.constraints.Size;
+
+@ManagedBean
+@SessionScoped
+public class PasswordValidationBean implements Cloneable, Serializable{
+ /**
+ *
+ */
+ private static final long serialVersionUID = 1952428504080910113L;
+ @Size(min = 5, max = 15, message = "Wrong size for password")
+ private String password="";
+ @Size(min = 5, max = 15, message = "Wrong size for confirmation")
+ private String confirm="";
+
+ @AssertTrue(message = "Different passwords entered!")
+ public boolean isPasswordsEquals() {
+ return password.equals(confirm);
+ }
+
+ public void storeNewPassword() {
+ FacesContext.getCurrentInstance().addMessage(null,
+ new FacesMessage(FacesMessage.SEVERITY_INFO, "Succesfully
changed!", "Succesfully changed!"));
+ }
+
+ public void setPassword(String password) {
+ this.password = password;
+ }
+
+ public void setConfirm(String confirm) {
+ this.confirm = confirm;
+ }
+
+ public String getPassword() {
+ return password;
+ }
+
+ public String getConfirm() {
+ return confirm;
+ }
+}
Property changes on:
branches/4.0.X/examples/validator-demo/src/main/java/org/richfaces/example/PasswordValidationBean.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added:
branches/4.0.X/examples/validator-demo/src/main/webapp/examples/passwordValidation.xhtml
===================================================================
---
branches/4.0.X/examples/validator-demo/src/main/webapp/examples/passwordValidation.xhtml
(rev 0)
+++
branches/4.0.X/examples/validator-demo/src/main/webapp/examples/passwordValidation.xhtml 2011-03-04
22:55:38 UTC (rev 22066)
@@ -0,0 +1,91 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<ui:composition
xmlns="http://www.w3.org/1999/xhtml"
+
xmlns:h="http://java.sun.com/jsf/html"
+
xmlns:f="http://java.sun.com/jsf/core"
+
xmlns:ui="http://java.sun.com/jsf/facelets"
+
xmlns:rich="http://richfaces.org/csv"
+
xmlns:rc="http://java.sun.com/jsf/composite/org.richfaces.showcase&q...
+ template="/layout/template.xhtml">
+ <ui:param name="title" value="<csv:graphValidator>
password validation" />
+ <!-- Page header -->
+ <ui:define name="header">
+ <style>
+.red {
+ color: red;
+}
+
+.green {
+ color: green;
+}
+</style>
+ <h1><csv:graphValidator> usage, password validation</h1>
+ </ui:define>
+ <!-- content -->
+ <ui:define name="content">
+ <h:panelGrid columns="2">
+ <f:facet name="head">
+ <h:outputText value="Actual values in the
model"/>
+ </f:facet>
+ <h:outputText value="Password:"/><h:outputText
value="#{passwordValidationBean.password}"/>
+ <h:outputText
value="Confirmation:"/><h:outputText
value="#{passwordValidationBean.confirm}"/>
+ </h:panelGrid>
+ <h:form>
+ Simple
+ <rich:graphValidator value="#{passwordValidationBean}"
id="gv">
+ <rich:messages />
+ <h:panelGrid columns="3">
+ <h:outputText value="Enter new password:" />
+ <h:inputSecret value="#{passwordValidationBean.password}"
+ id="pass" />
+ <rich:message for="pass" />
+ <h:outputText value="Confirm the new password:" />
+ <h:inputSecret value="#{passwordValidationBean.confirm}"
id="conf" />
+ <rich:message for="conf" />
+ </h:panelGrid>
+
+ <!--
+ <rc:test password="#{passwordValidationBean.password}"
confirmation="#{passwordValidationBean.confirm}" />
+ <rc:test1 bean="#{passwordValidationBean}" />
+ -->
+
+
+ <h:commandButton value="Store changes"
+ action="#{passwordValidationBean.storeNewPassword}" />
+ </rich:graphValidator>
+ </h:form>
+ <hr />
+ <h:form>
+ Test
+ <rich:graphValidator value="#{passwordValidationBean}"
id="gv">
+ <rich:messages />
+ <rc:test password="#{passwordValidationBean.password}"
+ confirmation="#{passwordValidationBean.confirm}" />
+
+
+ <h:commandButton value="Store changes"
+ action="#{passwordValidationBean.storeNewPassword}" />
+ </rich:graphValidator>
+ </h:form>
+ <hr />
+ <h:form>
+ Test A
+ <rich:graphValidator value="#{passwordValidationBean}"
id="gv">
+ <rich:messages />
+ <rc:test />
+
+ <h:commandButton value="Store changes"
+ action="#{passwordValidationBean.storeNewPassword}" />
+ </rich:graphValidator>
+ </h:form>
+ <hr />
+ <h:form>
+ Test1
+ <rich:graphValidator value="#{passwordValidationBean}"
id="gv">
+ <rich:messages />
+ <rc:test1 bean="#{passwordValidationBean}" />
+ <h:commandButton value="Store changes"
+ action="#{passwordValidationBean.storeNewPassword}" />
+ </rich:graphValidator>
+ </h:form>
+ </ui:define>
+</ui:composition>
\ No newline at end of file
Property changes on:
branches/4.0.X/examples/validator-demo/src/main/webapp/examples/passwordValidation.xhtml
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added:
branches/4.0.X/examples/validator-demo/src/main/webapp/resources/org.richfaces.showcase/test.xhtml
===================================================================
---
branches/4.0.X/examples/validator-demo/src/main/webapp/resources/org.richfaces.showcase/test.xhtml
(rev 0)
+++
branches/4.0.X/examples/validator-demo/src/main/webapp/resources/org.richfaces.showcase/test.xhtml 2011-03-04
22:55:38 UTC (rev 22066)
@@ -0,0 +1,30 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
+"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html
xmlns="http://www.w3.org/1999/xhtml"
+
xmlns:h="http://java.sun.com/jsf/html"
+
xmlns:f="http://java.sun.com/jsf/core"
+
xmlns:ui="http://java.sun.com/jsf/facelets"
+
xmlns:c="http://java.sun.com/jsp/jstl/core"
+
xmlns:composite="http://java.sun.com/jsf/composite"
+
xmlns:rich="http://richfaces.org/csv"
+ >
+<head>
+<title>panel</title>
+</head>
+<body>
+
+<composite:interface>
+</composite:interface>
+
+<composite:implementation>
+ <h:panelGrid columns="3">
+ <h:outputText value="Enter new password:" />
+ <h:inputSecret value="#{cc.attrs.password}" id="pass" />
+ <rich:message for="pass" />
+ <h:outputText value="Confirm the new password:" />
+ <h:inputSecret value="#{cc.attrs.confirmation}" id="conf"
/>
+ <rich:message for="conf" />
+ </h:panelGrid>
+</composite:implementation>
+</body>
+</html>
Property changes on:
branches/4.0.X/examples/validator-demo/src/main/webapp/resources/org.richfaces.showcase/test.xhtml
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added:
branches/4.0.X/examples/validator-demo/src/main/webapp/resources/org.richfaces.showcase/test1.xhtml
===================================================================
---
branches/4.0.X/examples/validator-demo/src/main/webapp/resources/org.richfaces.showcase/test1.xhtml
(rev 0)
+++
branches/4.0.X/examples/validator-demo/src/main/webapp/resources/org.richfaces.showcase/test1.xhtml 2011-03-04
22:55:38 UTC (rev 22066)
@@ -0,0 +1,40 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
+"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html
xmlns="http://www.w3.org/1999/xhtml"
+
xmlns:h="http://java.sun.com/jsf/html"
+
xmlns:f="http://java.sun.com/jsf/core"
+
xmlns:ui="http://java.sun.com/jsf/facelets"
+
xmlns:c="http://java.sun.com/jsp/jstl/core"
+
xmlns:composite="http://java.sun.com/jsf/composite"
+
xmlns:rich="http://richfaces.org/csv"
+ >
+<head>
+<title>panel</title>
+</head>
+<body>
+
+<composite:interface>
+ <composite:valueHolder targets="pass,conf" name="xxx" />
+</composite:interface>
+
+<composite:implementation>
+ #{cc.attrs.bean} a
+ <h:panelGrid columns="2">
+ <f:facet name="head">
+ <h:outputText value="Actual values in the
model"/>
+ </f:facet>
+ <h:outputText value="Password:"/><h:outputText
value="#{cc.attrs.bean.password}"/>
+ <h:outputText
value="Confirmation:"/><h:outputText
value="#{cc.attrs.bean.confirm}"/>
+ </h:panelGrid>
+
+ <h:panelGrid columns="3">
+ <h:outputText value="Enter new password:" />
+ <h:inputSecret value="#{cc.attrs.bean.password}" id="pass"
/>
+ <rich:message for="pass" />
+ <h:outputText value="Confirm the new password:" />
+ <h:inputSecret value="#{cc.attrs.bean.confirm}" id="conf"
/>
+ <rich:message for="conf" />
+ </h:panelGrid>
+</composite:implementation>
+</body>
+</html>
Property changes on:
branches/4.0.X/examples/validator-demo/src/main/webapp/resources/org.richfaces.showcase/test1.xhtml
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Modified:
branches/4.0.X/ui/validator/api/src/main/java/org/richfaces/el/ValueDescriptor.java
===================================================================
---
branches/4.0.X/ui/validator/api/src/main/java/org/richfaces/el/ValueDescriptor.java 2011-03-04
19:24:40 UTC (rev 22065)
+++
branches/4.0.X/ui/validator/api/src/main/java/org/richfaces/el/ValueDescriptor.java 2011-03-04
22:55:38 UTC (rev 22066)
@@ -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:
branches/4.0.X/ui/validator/api/src/main/java/org/richfaces/el/ValueExpressionAnalayser.java
===================================================================
---
branches/4.0.X/ui/validator/api/src/main/java/org/richfaces/el/ValueExpressionAnalayser.java 2011-03-04
19:24:40 UTC (rev 22065)
+++
branches/4.0.X/ui/validator/api/src/main/java/org/richfaces/el/ValueExpressionAnalayser.java 2011-03-04
22:55:38 UTC (rev 22066)
@@ -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:
branches/4.0.X/ui/validator/api/src/main/java/org/richfaces/validator/GraphValidatorState.java
===================================================================
---
branches/4.0.X/ui/validator/api/src/main/java/org/richfaces/validator/GraphValidatorState.java 2011-03-04
19:24:40 UTC (rev 22065)
+++
branches/4.0.X/ui/validator/api/src/main/java/org/richfaces/validator/GraphValidatorState.java 2011-03-04
22:55:38 UTC (rev 22066)
@@ -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:
branches/4.0.X/ui/validator/ui/src/main/java/org/richfaces/component/AbstractGraphValidator.java
===================================================================
---
branches/4.0.X/ui/validator/ui/src/main/java/org/richfaces/component/AbstractGraphValidator.java 2011-03-04
19:24:40 UTC (rev 22065)
+++
branches/4.0.X/ui/validator/ui/src/main/java/org/richfaces/component/AbstractGraphValidator.java 2011-03-04
22:55:38 UTC (rev 22066)
@@ -25,7 +25,6 @@
import java.lang.reflect.Modifier;
import java.util.Collection;
-import javax.el.ELContext;
import javax.el.ValueExpression;
import javax.faces.FacesException;
import javax.faces.application.FacesMessage;
@@ -38,8 +37,6 @@
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;
@@ -122,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);
}
@@ -161,7 +146,7 @@
}
super.processDecodes(context);
if (null != validatorState) {
- validatorState.setActive(false);
+ validatorState.setActive(wasActive);
}
}
@@ -170,41 +155,57 @@
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) {
Modified:
branches/4.0.X/ui/validator/ui/src/main/java/org/richfaces/el/CapturingELContext.java
===================================================================
---
branches/4.0.X/ui/validator/ui/src/main/java/org/richfaces/el/CapturingELContext.java 2011-03-04
19:24:40 UTC (rev 22065)
+++
branches/4.0.X/ui/validator/ui/src/main/java/org/richfaces/el/CapturingELContext.java 2011-03-04
22:55:38 UTC (rev 22066)
@@ -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:
branches/4.0.X/ui/validator/ui/src/main/java/org/richfaces/el/ValueExpressionAnalayserImpl.java
===================================================================
---
branches/4.0.X/ui/validator/ui/src/main/java/org/richfaces/el/ValueExpressionAnalayserImpl.java 2011-03-04
19:24:40 UTC (rev 22065)
+++
branches/4.0.X/ui/validator/ui/src/main/java/org/richfaces/el/ValueExpressionAnalayserImpl.java 2011-03-04
22:55:38 UTC (rev 22066)
@@ -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:
branches/4.0.X/ui/validator/ui/src/main/java/org/richfaces/validator/BeanValidatorServiceImpl.java
===================================================================
---
branches/4.0.X/ui/validator/ui/src/main/java/org/richfaces/validator/BeanValidatorServiceImpl.java 2011-03-04
19:24:40 UTC (rev 22065)
+++
branches/4.0.X/ui/validator/ui/src/main/java/org/richfaces/validator/BeanValidatorServiceImpl.java 2011-03-04
22:55:38 UTC (rev 22066)
@@ -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);
}
Deleted:
branches/4.0.X/ui/validator/ui/src/main/java/org/richfaces/validator/ClonedObjectResolver.java
===================================================================
---
branches/4.0.X/ui/validator/ui/src/main/java/org/richfaces/validator/ClonedObjectResolver.java 2011-03-04
19:24:40 UTC (rev 22065)
+++
branches/4.0.X/ui/validator/ui/src/main/java/org/richfaces/validator/ClonedObjectResolver.java 2011-03-04
22:55:38 UTC (rev 22066)
@@ -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: branches/4.0.X/ui/validator/ui/src/test/java/org/richfaces/el/ELTestBase.java
===================================================================
---
branches/4.0.X/ui/validator/ui/src/test/java/org/richfaces/el/ELTestBase.java 2011-03-04
19:24:40 UTC (rev 22065)
+++
branches/4.0.X/ui/validator/ui/src/test/java/org/richfaces/el/ELTestBase.java 2011-03-04
22:55:38 UTC (rev 22066)
@@ -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:
branches/4.0.X/ui/validator/ui/src/test/java/org/richfaces/el/TestCaptureEL.java
===================================================================
---
branches/4.0.X/ui/validator/ui/src/test/java/org/richfaces/el/TestCaptureEL.java 2011-03-04
19:24:40 UTC (rev 22065)
+++
branches/4.0.X/ui/validator/ui/src/test/java/org/richfaces/el/TestCaptureEL.java 2011-03-04
22:55:38 UTC (rev 22066)
@@ -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:
branches/4.0.X/ui/validator/ui/src/test/java/org/richfaces/el/ValueExpressionAnalayserTest.java
===================================================================
---
branches/4.0.X/ui/validator/ui/src/test/java/org/richfaces/el/ValueExpressionAnalayserTest.java 2011-03-04
19:24:40 UTC (rev 22065)
+++
branches/4.0.X/ui/validator/ui/src/test/java/org/richfaces/el/ValueExpressionAnalayserTest.java 2011-03-04
22:55:38 UTC (rev 22066)
@@ -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);
}
}