使用JSF在EL中用if-elseif-else表示 [英] The representation of if-elseif-else in EL using JSF

查看:346
本文介绍了使用JSF在EL中用if-elseif-else表示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下JSF代码包含两个单独的<c:if></c:if>.我们来看一下.

The following JSF code contains two separate <c:if></c:if>. Let's look at it.

<?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-else(Java上下文)来表示上述相同的<c:if></c:if>.


It simply displays value=10 on the JSF page at run time. I need to represent the above same <c:if></c:if> with the following if-elseif-else (Java context).

if(row.equals(10))
{
    //Do something...(JSF stuff)
}
else if(row.equals(15))
{
    //Do something...(JSF stuff)
}
else
{
    //Do something...(JSF stuff)
}


如何使用JSF用表达式语言(EL)表示它?


How can it be represented with Expression Language (EL) using JSF?

推荐答案

以下代码是最简单的方法:

The following code the easiest way:

 <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

Link for EL expression syntax. http://developers.sun.com/docs/jscreator/help/jsp-jsfel/jsf_expression_language_intro.html#syntax

这篇关于使用JSF在EL中用if-elseif-else表示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆