下面的JSF代码包含两个单独的<c:if></c:if>
。让我们来看看。
<?xml version='1.0' encoding='UTF-8' ?>
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:c="http://java.sun.com/jsp/jstl/core">
<h:head>
<title>JSF EL</title>
</h:head>
<h:body>
<h:form>
<c:set scope="request" var="row" property="x" value="10"/>
<c:if test="#{row==10}">
<h:outputLabel value="value = 10"/>
</c:if>
<c:if test="#{row==15}">
<h:outputLabel value="value = 15"/>
</c:if>
</h:form>
</h:body>
</html>
它只是在运行时在JSF页面上显示value=10。我需要用下面的if-elseif <c:if></c:if>
(Java )来表示上述相同的。
if(row.equals(10))
{
//Do something...(JSF stuff)
}
else if(row.equals(15))
{
//Do something...(JSF stuff)
}
else
{
//Do something...(JSF stuff)
}
如何使用JSF用表达式语言(EL)来表示它?
发布于 2011-11-14 17:46:19
以下代码是最简单的方法:
<h:outputLabel value="value = 10" rendered="#{row == 10}" />
<h:outputLabel value="value = 15" rendered="#{row == 15}" />
<h:outputLabel value="value xyz" rendered="#{row != 15 and row != 10}" />
EL表达式语法的链接。http://developers.sun.com/docs/jscreator/help/jsp-jsfel/jsf_expression_language_intro.html#syntax
发布于 2013-08-14 14:42:17
如果您想工作,可以使用EL,好像:
<h:outputLabel value="#{row==10? '10' : '15'}"/>
改变风格或类别:
style="#{test eq testMB.test? 'font-weight:bold' : 'font-weight:normal'}"
class="#{test eq testMB.test? 'divRred' : 'divGreen'}"
发布于 2015-09-07 05:06:54
可以在表达式语言中使用条件运算符"ELSE IF“,如下所示:
<p:outputLabel value="#{transaction.status.equals('PNDNG')?'Pending':
transaction.status.equals('RJCTD')?'Rejected':
transaction.status.equals('CNFRMD')?'Confirmed':
transaction.status.equals('PSTD')?'Posted':''}"/>
https://stackoverflow.com/questions/8125139
复制相似问题