CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/maven-org-eclipse-jetty--apache-jstl

Apache JSTL dependency aggregation module for Eclipse Jetty web applications

Pending
Overview
Eval results
Files

jstl-formatting.mddocs/

JSTL Formatting

The JSTL Formatting tag library provides internationalization and localization capabilities, including number formatting, date formatting, and message localization for building multilingual web applications.

Tag Library Declaration

<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>

Capabilities

Number Parsing

Parses string representations of numbers into numeric values with locale-aware formatting and error handling.

<fmt:parseNumber var="variableName" value="${stringValue}" />
<fmt:parseNumber var="variableName" value="${stringValue}" type="number|currency|percent" />
<fmt:parseNumber var="variableName" value="${stringValue}" pattern="customPattern" />
<fmt:parseNumber var="variableName" value="${stringValue}" parseLocale="${locale}" />

Usage Example:

<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>

<!-- Parse a currency string -->
<fmt:parseNumber var="price" value="$1,234.56" type="currency" />
<c:out value="Parsed price: ${price}" />

<!-- Parse with custom pattern -->
<fmt:parseNumber var="percentage" value="85.5%" pattern="#.#%" />
<c:out value="Parsed percentage: ${percentage}" />

<!-- Parse with error handling -->
<c:catch var="parseError">
    <fmt:parseNumber var="number" value="${userInput}" />
</c:catch>

<c:if test="${parseError != null}">
    <div class="error">Failed to parse number: ${parseError.message}</div>
</c:if>

Number Formatting

Formats numeric values as strings with locale-appropriate formatting, currency symbols, and percentage representation.

<fmt:formatNumber value="${numericValue}" />
<fmt:formatNumber value="${numericValue}" type="number|currency|percent" />
<fmt:formatNumber value="${numericValue}" pattern="customPattern" />
<fmt:formatNumber value="${numericValue}" maxFractionDigits="digits" />
<fmt:formatNumber value="${numericValue}" minFractionDigits="digits" />
<fmt:formatNumber value="${numericValue}" var="variableName" />

Usage Example:

<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>

<!-- Format as currency -->
<fmt:formatNumber value="${product.price}" type="currency" />

<!-- Format as percentage -->
<fmt:formatNumber value="${successRate}" type="percent" maxFractionDigits="1" />

<!-- Custom pattern -->
<fmt:formatNumber value="${distance}" pattern="#,##0.00 km" />

Date Parsing

Parses string representations of dates into Date objects with locale and pattern support.

<fmt:parseDate var="variableName" value="${dateString}" />
<fmt:parseDate var="variableName" value="${dateString}" type="date|time|both" />
<fmt:parseDate var="variableName" value="${dateString}" pattern="customPattern" />
<fmt:parseDate var="variableName" value="${dateString}" parseLocale="${locale}" />

Date Formatting

Formats Date objects as strings with locale-appropriate formatting and customizable patterns.

<fmt:formatDate value="${dateValue}" />
<fmt:formatDate value="${dateValue}" type="date|time|both" />
<fmt:formatDate value="${dateValue}" pattern="customPattern" />
<fmt:formatDate value="${dateValue}" dateStyle="default|short|medium|long|full" />
<fmt:formatDate value="${dateValue}" timeStyle="default|short|medium|long|full" />
<fmt:formatDate value="${dateValue}" var="variableName" />

Usage Example:

<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>

<!-- Format current date -->
<fmt:formatDate value="${now}" type="date" dateStyle="long" />

<!-- Format with custom pattern -->
<fmt:formatDate value="${event.startTime}" pattern="MMM dd, yyyy 'at' HH:mm" />

<!-- Format time only -->
<fmt:formatDate value="${appointment.time}" type="time" timeStyle="short" />

Message Localization

Retrieves localized messages from resource bundles based on the current locale.

<fmt:message key="messageKey" />
<fmt:message key="messageKey" var="variableName" />
<fmt:message key="messageKey" bundle="${bundleVar}" />
<fmt:message key="messageKey">
    <fmt:param value="${parameter1}" />
    <fmt:param value="${parameter2}" />
</fmt:message>

Locale Management

Sets and manages the current locale for formatting operations.

<fmt:setLocale value="${localeString}" />
<fmt:setLocale value="${localeString}" scope="page|request|session|application" />

Resource Bundle Management

Loads and manages resource bundles for message localization.

<fmt:bundle basename="bundleName">
    <!-- Scoped bundle usage -->
</fmt:bundle>

<fmt:setBundle basename="bundleName" var="bundleVar" />

Usage Example:

<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>

<!-- Set locale -->
<fmt:setLocale value="${user.preferredLocale}" />

<!-- Load resource bundle -->
<fmt:setBundle basename="messages" var="msgs" />

<!-- Display localized messages -->
<fmt:message key="welcome.message" bundle="${msgs}">
    <fmt:param value="${user.name}" />
</fmt:message>

<!-- Conditional locale formatting -->
<c:choose>
    <c:when test="${user.locale == 'en_US'}">
        <fmt:formatDate value="${order.date}" pattern="MM/dd/yyyy" />
    </c:when>
    <c:otherwise>
        <fmt:formatDate value="${order.date}" pattern="dd/MM/yyyy" />
    </c:otherwise>
</c:choose>

Error Handling

JSTL formatting tags can throw the following exceptions:

  • ParseException: When parsing fails due to invalid format
  • IllegalArgumentException: Invalid pattern or parameter values
  • MissingResourceException: When resource bundles or keys are not found
  • JspException: General JSP processing errors

Common error scenarios:

  • Invalid date/number formats in parsing operations
  • Missing or malformed resource bundle files
  • Incorrect locale specifications
  • Invalid pattern strings for custom formatting

Install with Tessl CLI

npx tessl i tessl/maven-org-eclipse-jetty--apache-jstl

docs

index.md

jetty-integration.md

jstl-core.md

jstl-formatting.md

tile.json