level55
level55

Reputation: 89

handle null recursively in freemarker

I want to execute eval on a string "bean.data.id", but "bean.data" is null. is there any way to make this expression do not throw exception? or what is the right way to handle this? Thanks a lot!

${name?eval}

name = 'bean.data.id'
bean = {"data": null}

Upvotes: 1

Views: 77

Answers (1)

ddekany
ddekany

Reputation: 31122

You could do this (assuming printing nothing on null is fine):

${'(${name})!'?eval}

Upvotes: 2

Related Questions