How to use EL conditional operator in JSF componen

2019-02-15 09:27发布

问题:

I need to dynamically choose the width of a <p:panelGrid> based on a backing bean property. However it is not working for me. I have a feeling that I have some syntax error in my code.

<p:panelGrid style="width:#{myBean.fromCCRM} ?70%:90%">
    ...
</p:panelGrid>

回答1:

The entire statement needs to go inside #{...}.

style="width:#{myBean.fromCCRM ? '70%' : '90%'}"