A Renderer for Encoding and Decoding
To customize the way the value for an
input component
is entered, we must develop a custom renderer that implements the
decoding behavior in addition to the encoding behavior. An example is
a custom renderer for the UIInput component that
lets the user pick a date by selecting the year, month, and day from
three selection lists, as shown in Figure 13-2.
![]() |
Because the date value is rendered as three selection lists,
it’s sent to the server as three separate
parameters. The custom renderer reads all three and creates a single
java.util.Date value that the input component can
handle.
Before we dig into the code, let’s see how the custom renderer can be used. Example 13-2 shows the JSP page using the custom action element that ties together the custom renderer and the input component.
<%@ page contentType="text/html" %> <%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %> <%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %> <%@ taglib uri="http://mycompany.com/jsftaglib" prefix="my" %> <jsp:useBean id="now" scope="request" class="java.util.Date" /> <f:view> <html> <body> <h:form> <my:inputDatePicker value="#{myDate}" startYear="#{now.year + 1900 - 2}" years="10" /> <h:outputText value="#{myDate}" ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access
