我有一个页面,用户可以通过Android,iPhone,BlackBerry或未知的浏览器访问该页面。我有4 rich:panel秒,每个平台一个,而后者是一个通用的平台。
rich:panel
编码:
<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仅当没有其他渲染时,才可以渲染最后一个?
到目前为止,标题中所述的问题可以具体回答为:
<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>:
<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}映射获取请求标头的较短方法。
#{header}