O'Reilly logo

JavaServer Faces by Hans Bergsten

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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}"> ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required