History | Log In     View a printable version of the current page.  
Issue Details (XML | Word | Printable)

Key: OGNL-105
Type: Bug Bug
Status: Resolved Resolved
Resolution: Fixed
Priority: Major Major
Assignee: Jesse Kuhnert
Reporter: Kalle Korhonen
Votes: 0
Watchers: 2
Operations

If you were logged in you would be able to see more operations.
OGNL

Compiled OGNL using bracket notation requires #this

Created: 03/Jul/07 11:56 AM   Updated: 15/Jul/07 02:19 PM
Component/s: ExpressionCompiler
Affects Version/s: 2.7.1
Fix Version/s: 2.7.1

Environment: Any, with compiled expressions


 Description  « Hide
Related to OGNL-97, but somewhat more complex case: Referring to an object's property via bracket notation only works if we you use #this to denote the name of property, e.g. object[#this.propertyKey]. Below a unit test that shows the interpreted expression, and the equivalent compiled expression that fails without #this (it evaluates to the object itself).

import java.util.HashMap;
import java.util.Map;

import org.apache.tapestry.services.impl.OgnlClassResolver;

import junit.framework.TestCase;

import ognl.ClassResolver;
import ognl.Node;
import ognl.Ognl;
import ognl.OgnlContext;
import ognl.OgnlException;
import ognl.enhance.ExpressionAccessor;

public class OgnlTest extends TestCase {
private TestObject testObject = new TestObject("propertyValue");

public class TestObject {
String property;
public TestObject(String property) {
this.property = property;
}

public String getProperty() {
return property;
}
}

public TestObject getObject() {
return testObject;
}

public String getPropertyKey() {
return "property";
}

public void testOgnl() throws OgnlException {
assertEquals("propertyValue", Ognl.getValue("object[propertyKey]", this));
}

public void testEnhancedOgnl() throws Exception {
// Succeeds
context = (OgnlContext)Ognl.createDefaultContext(this, ognlResolver);
expression = Ognl.compileExpression(context, this, "object[#this.propertyKey]");
assertEquals("propertyValue", Ognl.getValue(expression.getAccessor(), context, this)) ;

// Fails
context = (OgnlContext)Ognl.createDefaultContext(this, ognlResolver);
expression = Ognl.compileExpression(context, this, "object[propertyKey]");
assertEquals("propertyValue", Ognl.getValue(expression.getAccessor(), context, this)) ;
}
}


 All   Comments   Change History      Sort Order:
There are no comments yet on this issue.