org.apache.myfaces.trinidad.convert

## Interface ClientConverter

-     public interface ClientConverter

  Interface implemented by Objects that wish to perform client-side conversion in addition to server-side conversion. Client side conversion should always be the same as or more lenient than the server-side conversion.

  One of the benefits of Apache Trinidad is that it supports client-side versions of converters and validators. This means that errors can be caught on the client and a round trip avoided. This interface can be used to add client-side conversion to a converter.

  The basic idea of Apache Trinidad client-side conversion is that it works on the client in a very similar way to how it works on the server, except the language on the client is javascript instead of java. Apache Trinidad supports javascript Converter objects that support the methods getAsString() and getAsObject(). A Converter can throw a ConverterException.

  Let's say you've written a javax.faces.convert.Converter implementation and now you want to add client-side conversion. The first thing to do is write a version of the converter in javascript. Here is the javascript code for the converter "interface".

       /**
        * Converter "interface" similar to javax.faces.convert.Converter,
        * except that all relevant information must be passed to the constructor
        * as the context and component are not passed to the getAsString or getAsObject method
        *
        * /
       function Converter()
       {
       }

        /**
        * Convert the specified model object value, into a String for display
        *
        * @param value Model object value to be converted
        * /
       Converter.prototype.getAsString = function(value){}

       /**
        * Convert the specified string value into a model data object
        * which can be passed to validators
        *
        * @param value String value to be converted
        * /
       Converter.prototype.getAsObject = function(value){}

  Converters can throw a ConverterException, here is the signature:
  - ConverterException(detail)
    - detail - Localized detail message text
  The method
  - `getClientLibrarySource()` is expected to return a library that has an implementation of the javascript Converter object.
  - `getClientConversion()` is expected to return a javascript constructor which will be used to instantiate an instance of the converter.
  - `getClientScript()` can be used to write out inline js.
  - `getClientImportNames()` is used to import the built-in scripts provided by Apache Trinidad.

  See Also:
    `Converter`

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static String` | `ALERT_FORMAT_KEY`

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `String` | `getClientConversion(javax.faces.context.FacesContext context, javax.faces.component.UIComponent component)` Called to retrieve the appropriate client conversion code for the node and context.
    `Collection<String>` | `getClientImportNames()` Supports importing the built-in scripts provided by Apache Trinidad.
    `String` | `getClientLibrarySource(javax.faces.context.FacesContext context)` Gets the URI specifying the location of the js lib resource.
    `String` | `getClientScript(javax.faces.context.FacesContext context, javax.faces.component.UIComponent component)` Opportunity for the ClientConverter to return script content.

- - ### Field Detail

    - #### ALERT_FORMAT_KEY

          static final String ALERT_FORMAT_KEY

      See Also:
        Constant Field Values

  - ### Method Detail

    - #### getClientLibrarySource

          String getClientLibrarySource(javax.faces.context.FacesContext context)

      Gets the URI specifying the location of the js lib resource. Only the first reference to a library will result in its being imported.

    - #### getClientImportNames

          Collection<String> getClientImportNames()

      Supports importing the built-in scripts provided by Apache Trinidad. It can be used to ensure that a Javascript function is available before using it in a Javascript handler. Only the first reference to a script will result in its being imported.

      If this function returns null "Converter()" will be used.

      Returns:
        a collection of function names

    - #### getClientScript

          String getClientScript(javax.faces.context.FacesContext context,
                               javax.faces.component.UIComponent component)

      Opportunity for the ClientConverter to return script content. For HTML, this will be javascript that will be embedded in a script tag. For HTML this method is expected to return an implementation of the javascript Converter object.

      Do not rely on this content being ppr updated.

      This method will be called once per converter instance. Content that should only be written once per request should only be returned once.

    - #### getClientConversion

          String getClientConversion(javax.faces.context.FacesContext context,
                                   javax.faces.component.UIComponent component)

      Called to retrieve the appropriate client conversion code for the node and context. For HTML, this will be javascript that will be embedded in a script tag. For HTML this method is expected to return a constructor of the javascript Converter object returned by getClientScript().

Copyright © 2001-2017 The Apache Software Foundation. All Rights Reserved.