Reputation: 133
I am trying to write a expression with the unified expression language in JSF that states that, if an image is not empty, then use it otherwise use a default one.
#{not empty image ? image : #{bean.directory}image.jpg}
The problem is the default one can be accessed only by calling a certain function "#{bean.directory}
" to retrieve the directory. I am getting ERROR PARSING
.
Any idea how to resolve this?
Upvotes: 1
Views: 1730
Reputation: 8498
Your mistake is, that you nesting expressions.
<NEW_EL1>not empty image ? image : <NEW_EL2>bean.directory</END_EL2>image.jpg</END_EL2>
This is not supported.
Related to your expression:
#{empty image ? bean.directory : image}#{empty image ? 'image.jpg'}
Another example:
#{((fooBean.random % 4) == 0 ? 'completely divisible by 4' : 'not completely divisible by 4'}
Upvotes: 1
Reputation: 12870
I don't know an easy way to concatenate strings in EL, so this piece is somewhat clumsy but should work (I assume image is some kind of variable with full file name while 'image.jpg' is your default file name to be looked up in bean.directory):
#{empty image ? bean.directory : image}#{empty image ? 'image.jpg' : ''}
Upvotes: 2