Skip to content

Commit 1dfbbde

Browse files
committed
Merge pull request ocpsoft#38 from chkal/el-fix
TypeBasedExpression now creates raw expressions without #{...}
2 parents d27091e + b66a6ca commit 1dfbbde

4 files changed

Lines changed: 18 additions & 5 deletions

File tree

‎api-el/src/main/java/org/ocpsoft/rewrite/el/TypeBasedExpression.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ private String lookupBeanName()
8282

8383
// create the complete EL expression including the component
8484
String el = new StringBuffer()
85-
.append("#{").append(beanName).append('.').append(component).append('}')
85+
.append(beanName).append('.').append(component)
8686
.toString();
8787

8888
if (log.isTraceEnabled()) {

‎api-el/src/test/java/org/ocpsoft/rewrite/el/TypeBasedExpressionTest.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public class TypeBasedExpressionTest
2626
public void testTypeBasedExpression() throws Exception
2727
{
2828
TypeBasedExpression expression = new TypeBasedExpression(BeanWithElBeanNameAnnotation.class, "sayHello");
29-
assertEquals("#{myBean.sayHello}", expression.getExpression());
29+
assertEquals("myBean.sayHello", expression.getExpression());
3030
}
3131

3232
@ELBeanName("myBean")

‎integration-faces/src/main/java/org/ocpsoft/rewrite/faces/FacesExpressionLanguageProvider.java‎

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,10 +102,11 @@ public Object evaluateMethodExpression(String expression) throws UnsupportedEval
102102
@Override
103103
public Object evaluateMethodExpression(String expression, Object... values) throws UnsupportedEvaluationException
104104
{
105+
String el = toELExpression(expression);
105106
FacesContext facesContext = getFacesContext();
106107
ELContext elContext = facesContext.getELContext();
107108
ExpressionFactory expressionFactory = facesContext.getApplication().getExpressionFactory();
108-
MethodExpression methodExpression = expressionFactory.createMethodExpression(elContext, expression,
109+
MethodExpression methodExpression = expressionFactory.createMethodExpression(elContext, el,
109110
Object.class, new Class[values.length]);
110111
return methodExpression.invoke(elContext, values);
111112
}
@@ -115,8 +116,9 @@ public Object evaluateMethodExpression(String expression, Object... values) thro
115116
*/
116117
private ValueExpression getValueExpression(FacesContext facesContext, String expression)
117118
{
119+
String el = toELExpression(expression);
118120
ExpressionFactory expressionFactory = facesContext.getApplication().getExpressionFactory();
119-
return expressionFactory.createValueExpression(facesContext.getELContext(), expression, Object.class);
121+
return expressionFactory.createValueExpression(facesContext.getELContext(), el, Object.class);
120122
}
121123

122124
/**
@@ -133,4 +135,15 @@ private FacesContext getFacesContext()
133135
}
134136
return facesContext;
135137
}
138+
139+
/**
140+
* Adds #{..} to the expression if required
141+
*/
142+
private String toELExpression(String s)
143+
{
144+
if (s != null && !s.startsWith("#{")) {
145+
return "#{" + s + "}";
146+
}
147+
return s;
148+
}
136149
}

‎integration-faces/src/test/java/org/ocpsoft/rewrite/faces/resolver/FacesBeanNameResolverTest.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public static WebArchive getDeployment()
4949
}
5050

5151
@Test
52-
public void testSpringFeatures()
52+
public void testFacesBeanNameResolverFeatures()
5353
{
5454
HttpAction<HttpGet> action = get("/name/christian");
5555
Assert.assertEquals(200, action.getResponse().getStatusLine().getStatusCode());

0 commit comments

Comments
 (0)