Handling Localized Application Input

The locale also plays a role when input is being processed. As I mentioned earlier, dates and numbers are written according to different rules in different parts of the world, so input must be parsed according to the rules for the current locale.

All JSF input components use the current locale when they parse input, so there’s really nothing you need to do beyond what we’ve already covered. To verify this, let’s use an internationalized version of the entry form area (Example 11-3) and see what happens.

Example 11-3. Internationalized version of the entry form area page (expense/stage5/entryFormArea.jsp)
<%@ page contentType="text/html" %>
<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>

<f:view locale="#{userProfile.locale}">
  <f:loadBundle basename="labels" var="labels" />
  <h:form>
    <h:outputText value="#{labels.reportTitleLabel}" />
    <h:inputText id="title" size="30" required="true"
      value="#{reportHandler.currentReport.title}" />
    <h:message for="title" />
    <br>
    <h:outputText value="#{labels.reportEntryLabel}" />
    <br>
    <h:outputText value="#{labels.entryDateLabel}" />
    <h:inputText id="date" size="10" required="true"
      value="#{entryHandler.currentEntry.date}">
      <f:convertDateTime datestyle="short" /> </h:input_text> <h:message for="date" /> <br> <h:outputText value="#{labels.entryTypeLabel}" /> <h:selectOneMenu id="type" required="true" value="#{entryHandler.currentEntry.type}"> ...

Get JavaServer Faces now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.