File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Spring and the fly likes Issue with Expression parsing using SpEL Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Spring
Bookmark "Issue with Expression parsing using SpEL " Watch "Issue with Expression parsing using SpEL " New topic

Issue with Expression parsing using SpEL

Ravi Valigari

Joined: Oct 27, 2010
Posts: 1
My requirement is to use the SpEL with custom variable format #{VarName} in the expression without rootObject in the evaluation context.

It works when i go with the default variable format that is #variableName with out any issues. But when i start using the format #{variablename} it is throwing me the following exception.

org.springframework.expression.spel.SpelEvaluation Exception: EL1007Epos 0): Field or property 'loginId' cannot be found on null

I'm attaching the source for both the cases here,

Case 1: this works
With default variable format, that is #variableName

Case 2: this is throwing SpelEvaluationException
With custom variable format that is, #{variableName}

After debugging it is looking like there is some problem with PropertyOrFieldReference(SpellNodeImpl). getValueInternal() method, where rootObject is considered for getting the variable value, where as rootObject is null in my case.

It should pick the values from the map which is in EvaluationContext, and should not consider rootObject.

Please help me to know if this is a bug in Spring Code or i'm missing anything.

Johan Kustermans

Joined: Apr 06, 2012
Posts: 1
For the ones ending up here looking for a solution in the template case:

1. Use the map as rootObject in your evalutationContext and add a MapAccesor to your evalutionContext:

2. Refer to the variables inside #{ .. } by prefixing with #.

It looks silly but as I see it, the # prefix is used here in 2 guises. In front of #{..} it is used to indicate a expression block inside a template, and inside #{..} it is used to indicate a variable inside the evalutioncontext on which you can let loose more complex spel expressions if needed. It is more clear if you use ${..} for the expression block (change your templated parser context for his to work):

I agree. Here's the link:
subject: Issue with Expression parsing using SpEL
It's not a secret anymore!