![](/img/trans.png)
[英]What is the equivalent of JSTL <c:forTokens> in JSF or PrimeFaces?
[英]how to separate values in variable from fortokens in jstl
我被困在使用JSTL
forTokens
向variable
forTokens
<c:forTokens items="${row.date}" delims="/" var="values">
<c:set var="date" value="${values}"></c:set>
<c:out value="${date }"></c:out>
</c:forTokens>
通過上面的代碼,我得到了一些類似的東西:
19 April 2014
現在我想知道如何獲得:
字符串日=“ 19”
字符串月份=“四月”
字符串年份=“ 2014”
來自${values}
,就像Array
更新:
在JSP中,我添加了以下代碼:
<%--You can use your date instead of this--%>
<% pageContext.setAttribute("date", new Date()); %>
<fmt:formatDate value="${date}" pattern="dd" var="day" /></p>
The day is: <c:out value="${day}"/>
<fmt:formatDate value="${date}" pattern="MMMM" var="month" /></p>
The month is: <c:out value="${month}"/>
<fmt:formatDate value="${date}" pattern="yyyy" var="year" /></p>
The year is: <c:out value="${year}"/>
它的工作原理是:
The day is: 19
The month is: April
The year is: 2014
在我的pom.xml
我具有以下依賴關系:
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.0.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet.jsp</groupId>
<artifactId>javax.servlet.jsp-api</artifactId>
<version>2.3.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
<c:forTokens items="${row.date}" delims="/" var="values" varStatus="status">
<c:if test="${status.index == 0}">
<c:set var="day" value="${values}"></c:set>
</c:if>
<c:if test="${status.index == 1}">
<c:set var="month" value="${values}"></c:set>
</c:if>
<c:if test="${status.index == 2}">
<c:set var="year" value="${values}"></c:set>
</c:if>
</c:forTokens>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.