I have JSF 2.2, PrimeFaces 5.0 web application.
On my page I need to conditionally set <ui:param/>
. The problem is that a standard ternary operator isn't enough, because I have more than 2 options to choose. This single page serves as an edit and create page for 2 types of users: regular user and a physician.
Here is what I tried:
<ui:param name="edit_title"
value="#{empty dto.id ?
(bean.isPhysician ? msg.physicianNewTitle : msg.userNewTitle) :
(bean.isPhysician ? msg.physicianEditTitle : msg.userEditTitle)}" />
The result shows wrong title, when dto.id
is empty and bean.isPhysician
is false and I can't find a problem or a better solution. Tried to set it conditionally like it was said here, but it doesn't work for some reason.
Does anyone know how to solve this kind of trouble?
Every useful answer is highly appreciated and evaluated.
Thank you.
Well, guys, I have found what was causing the wrong behavior and it has nothing to do with nested ternary operator. It was just wrong calculation of isPhysician variable.
So, if you need to choose from more than 2 conditions in a view - try making it like this:
<ui:param name="edit_title"
value="#{empty dto.id ?
(bean.isPhysician ? msg.physicianNewTitle : msg.userNewTitle) :
(bean.isPhysician ? msg.physicianEditTitle : msg.userEditTitle)}" />
Or simply move your logic to a bean. Hope this helps somebody.
Cheers.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With