Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Issue with Expression parsing using SpEL

 
Ravi Valigari
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

Thanks
Ravi
 
Johan Kustermans
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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):






 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic