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.

  1. under /web-inf create directory tags.
  2. create tag file localdate.tag inside tags directory.
  3. 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}"/> 
  4. 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

Popular posts from this blog

apache - PHP Soap issue while content length is larger -

asynchronous - Python asyncio task got bad yield -

javascript - Complete OpenIDConnect auth when requesting via Ajax -