previous | index | next

Supplying Attributes to Converters

Suppose the getAsString method in the CreditCardConverter class allowed the formatting of credit card numbers using separators besides blanks.

JSF pages could then supply the separator character as an attribute value:

     <h:outputText value="#{payment.card}">
        <f:converter converterId="com.corejsf.CreditCard"/>
        <f:attribute name="separator" value="-"/>
     </h:outputText>

In the converter, retrieve the attribute using:

     separator = (String) component.getAttributes().get("separator");

The same thing can be accomplished more elegantly with custom tags (chapter 9).


previous | index | next