What Happens at Runtime

Validating and Converting Input 6-7 ■ In the window, select Converters and click New. Click Help or press F1 for additional help in registering the converter. To create a client-side version of the converter: ■ Write a JavaScript version of the converter, passing relevant information to a constructor. Example 6–6 shows the code to implement the interface org.apache.myfaces.trinidad.convert.ClientConverter, which has two methods. The first method is getClientScript, which returns an implementation of the JavaScript Converter object. The second method is getClientConversion, which returns a JavaScript constructor that is used to instantiate an instance of the converter. Example 6–6 Interface Converter function TrConverter { } Convert the specified model object value, into a String for display param value Model object value to be converted param label label to identify the editableValueHolder to the user return the value as a string or undefined in case of no converter mechanism is available see TrNumberConverter. TrConverter.prototype.getAsString = functionvalue, label{} Convert the specified string value into a model data object which can be passed to validators param value String value to be converted param label label to identify the editableValueHolder to the user return the converted value or undefined in case of no converter mechanism is available see TrNumberConverter. TrConverter.prototype.getAsObject = functionvalue, label{} The TrConverter interface can throw a TrConverterException exception, which should contain a TrFacesMessage error message. Example 6–7 shows the signature for TrFacesMessage and Example 6–8 shows the signature for TrFacesException. Example 6–7 TrFacesMessage Signature Message similar to javax.faces.application.FacesMessage param summary - Localized summary message text param detail - Localized detail message text param severity - An optional severity for this message. Use constants SEVERITY_INFO, SEVERITY_WARN, SEVERITY_ERROR, and SEVERITY_FATAL from the FacesMessage class. Default is SEVERITY_INFO function TrFacesMessage summary, detail, severity