2013-02-15 91 views
2

好我有一個名爲FiscalMonth枚舉:使用JSTL訪問枚舉值?

Oct(1), 
Nov(2), 
Dec(3), 
Jan(4), 
Feb(5), 
Mar(6), 
Apr(7), 
May(8), 
Jun(9), 
Jul(10), 
Aug(11), 
Sep(12); 

我需要訪問#的在JSTL ...右now..im只運用字符串作爲這樣..

<c:forEach var="month" items="${monthList}" end="11"> 

<c:choose> 
    <c:when test="${fn:substring(month,0,1) == 'O'}"> 
     "${fn:substring(month,0,1)}${fn:substring(year,2,4)}", "tooltext": "${month} ${year}}"}); 
    </c:when> 
    <c:otherwise> 
     "${fn:substring(month,0,1)}", "tooltext": "${month} "}); 
    </c:otherwise> 
</c:choose> 

我該如何獲取枚舉#的?謝謝

回答

5

如果您可以修改FiscalMonth類,請添加一個名爲getNumber()的方法,該方法返回月份編號。然後你可以像這樣訪問EL中的月份編號:${month.number}。您也可以用getWhatever()month.whatever替換getNumber()month.number

回家的信息是,枚舉類型幾乎是任何其他類。他們可以有方法,實例變量等。