I have a page that the user can access via Android, iPhone, BlackBerry or via an unknown browser. I have 4 rich:panel
s, one for each platform and the latter is a generic one.
The code:
<rich:panel id="dlAndroid" rendered="#{fn:containsIgnoreCase(request.getHeader('User-Agent'), 'Android')}">
...
</rich:panel>
<rich:panel id="dlIphone" rendered="#{fn:containsIgnoreCase(request.getHeader('User-Agent'), 'iPhone')}">
...
</rich:panel>
<rich:panel id="dlBlackberry" rendered="#{fn:containsIgnoreCase(request.getHeader('User-Agent'), 'BlackBerry')}">
...
</rich:panel>
<rich:panel id="dlGeneric" rendered="#{ ---> WHAT TO WRITE HERE? <--- }">
How can I render the last rich:panel
only if none of the others has been rendered?
To the point, your question as stated in the title can concretely be answered as:
<rich:panel binding="#{panel1}" ...>
...
</rich:panel>
<rich:panel binding="#{panel2}" ...>
...
</rich:panel>
<rich:panel binding="#{panel3}" ...>
...
</rich:panel>
<rich:panel ... rendered="#{not panel1.rendered and not panel2.rendered and not panel3.rendered}">
...
</rich:panel>
However, in this particular case it's perhaps nicer to alias those long winded expressions with <c:set>
:
<c:set var="android" value="#{fn:containsIgnoreCase(header['User-Agent'], 'Android')}" scope="request" />
<c:set var="iPhone" value="#{fn:containsIgnoreCase(header['User-Agent'], 'iPhone')}" scope="request" />
<c:set var="blackBerry" value="#{fn:containsIgnoreCase(header['User-Agent'], 'BlackBerry')}" scope="request" />
<rich:panel ... rendered="#{android}">
...
</rich:panel>
<rich:panel ... rendered="#{iPhone}">
...
</rich:panel>
<rich:panel ... rendered="#{blackBerry}">
...
</rich:panel>
<rich:panel ... rendered="#{not android and not iPhone and not blackBerry}">
...
</rich:panel>
Note that there's a shorter way to get the request header by the implicit #{header}
map.
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