问题描述
我有一个页面,用户可以通过Android,iPhone,BlackBerry或未知浏览器访问该页面。我有4个 rich:panel
s,每个平台一个,后者是通用的。
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.
代码:
<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? <--- }">
如何渲染最后的 rich:panel
只有在没有其他人被渲染的情况下?
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>
然而,在这个特殊情况下,用< c:set> :
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>
请注意,通过隐式获取请求标头的方法较短# {header}
map。
Note that there's a shorter way to get the request header by the implicit #{header}
map.
这篇关于如果只渲染另一个组件,如何渲染组件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!