el-spec
el-spec copied to clipboard
Accessing properties of a bean implementing the Map interface
Hello all,
we are trying to access properties of a Java-bean implementing the Map interface with an EL-expression like "#{bean.property}" which always yields null. Is this a bug or is it specified? Please see the following testcase for details.
public class ElTestCase {
private ELProcessor elProcessor;
@Before
public void before() {
elProcessor = new ELProcessor();
TestMapWithProperty test = new TestMapWithProperty("hello");
test.put("entry", "world");
elProcessor.defineBean("test", test);
}
@Test
public void property() {
// fails because the expression evaluates to null
assertThat( elProcessor.eval("test.property"), is("hello") );
}
@Test
public void property_II() {
// fails because the expression evaluates to null
assertThat( elProcessor.eval("test['property']"), is("hello") );
}
@Test
public void entry() {
// success
assertThat( elProcessor.eval("test.entry"), is("world") );
}
public static class TestMapWithProperty extends HashMap<String, String> {
private String property;
public TestMapWithProperty(String property) {
this.property = property;
}
public String getProperty() {
return property;
}
}
}
The EL-Implementation we are using is
<dependency>
<groupId>org.glassfish</groupId>
<artifactId>javax.el</artifactId>
<version>3.0.1-b10</version>
</dependency>