0

How can I do this? I want to show a value from a entity, not a string, but how can I do this as a valid code?

itemLabel="#{mandatoryFriendship.receiver == loginBean.currentMandatory ? mandatoryFriendship.sender.surname  : mandatoryFriendship.receiver.surname mandatoryFriendship.receiver.name}"

Thank you for you help

internet
  • 385
  • 1
  • 8
  • 27
  • your question is not clear, to show a value of a entity only use `#{entity.property}` , supposing htat your `entity` is in the scope of JSF beans – Leo Mar 01 '14 at 17:23
  • EL ternary operator works fine. Try expression without string concatenation in else part. See [working example](http://stackoverflow.com/questions/4628145/jsf-2-el-ternary-operator-question) – Vasil Lukach Mar 01 '14 at 19:45
  • No, i want not to display a string, I want to display the property of a bean. Something like this `code`itemLabel="#{mandatoryFriendship.receiver == loginBean.currentMandatory} ? #{mandatoryFriendship.sender.surname} : #{mandatoryFriendship.receiver.surname} #{mandatoryFriendship.receiver.name}"`code` – internet Mar 10 '14 at 21:20
  • the problem isnt the #{entity.property} ! The problem is TWO #{entity.property} in one condition – internet Mar 10 '14 at 22:08

1 Answers1

3

Assuming at least EL 2.2 and that the names are non-null Strings you could have an expression of the form:

#{condition ? str0 : str1.concat(str2)}

For an older version (or null Strings) you could use:

#{condition ? str0 : str1}#{condition ? str0 : str2}
McDowell
  • 107,573
  • 31
  • 204
  • 267