jsp - Taglib to display java.time.LocalDate formatted -
i display formatted java.time.localdate
in jsp. know taglib use this?
for java.util.date
using <%@ taglib prefix="fmt" uri="http://java.sun.com/jstl/fmt" %>
. similar java.time.localdate
exist?
afsun's hints inspired me create quick solution.
- under
/web-inf
create directorytags
. - create tag file
localdate.tag
insidetags
directory. put bellow code tag file:
<%@ tag body-content="empty" pageencoding="utf-8" trimdirectivewhitespaces="true" %> <%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %> <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> <%@ attribute name="date" required="true" type="java.time.localdate" %> <%@ attribute name="pattern" required="false" type="java.lang.string" %> <c:if test="${empty pattern}"> <c:set var="pattern" value="mm/dd/yyyy"/> </c:if> <fmt:parsedate value="${date}" pattern="yyyy-mm-dd" var="parseddate" type="date"/> <fmt:formatdate value="${parseddate}" type="date" pattern="${pattern}"/>
go jsp file in want display
java.time.localdate
.4.1. add taglib directive
<%@ taglib prefix="tags" tagdir="/web-inf/tags" %>
@ top of file.4.2. use
localdate
tag follows:<tags:localdate date="${yourdatetoprint}"/>
<tags:localdate date="${yourdatetoprint}" pattern="${yourpatternformat}"/>
Comments
Post a Comment