Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Dynamic Expression Language Evaluation  RSS feed

 
Reginald Blank
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is it possible to achieve something like this:



Where myDataPath is a path on myObject, e.g. if myDataPath = "address.zipCode" the above turns into:



If it isn't possible I guess I could write a tag to evaluate the expression of set it in the model using Apache Commons bean library?
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65833
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
Reginald Blank
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks that works.
I didn't realise that worked with point separated paths.



 
Reginald Blank
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Spoke to soon - it doesn't work after all. I get the following error:

Property 'address.zipCode' not found on type MyClass

Where MyClass has an inherited field called address (of a class that implements map) with a pair stored under the key zipCode. The value part of the pair is a class that returns a value via the toString method.

It works if I do the path directly in EL, i.e.



It also works if I do:



But the following doesn't work:

 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65833
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Guess you'll have to split it on the dot character. The JSTL split function may be helpful.
 
Reginald Blank
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I can imagine building a string of the above from using the split function and a for loop, but how do I then get Jasper to evaluate the string as an expression?
 
Reginald Blank
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I came up with the following 'interesting' solution which I guess could be implemented in a custom tag to make it slightly less ugly:

 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65833
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'd recommend not resorting to scriptlets!

If you know there will be two parts, using JSTL split it could be something like:which to me isn't anywhere near readable enough to even approach being reasonable.

What I'd do is to refactor the way that the data is passed to the JSP to avoid having to use such shenanigans at all. My motto: smart controllers, dumb JSPs.

Failing that, I'd probably create a custom EL function or a custom tag to handle the situation in a readable manner. (But only as a last resort.)
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!