Designer 10.7 | webMethods CAF and OpenUI Development | Using Converters and Validators | Creating a Custom Converter
 
Creating a Custom Converter
To create a custom converter, you need Java coding experience. Composite Application Framework provides some initial code to get you started. A custom converter is valid only for the portlet in which it is created. If you plan to use a particular converter in many portlets, create your own library and load it through the project.
*To create a custom converter
1. Open a CAF view in the design canvas and select the control for which you want to create a custom converter.
2. In the Properties view, click the General tab.
3. In the ID field, type a unique ID for the converter.
4. In the design canvas, right-click the control, and then click Lifecycle > Custom Converter.
Composite Application Framework creates Java code in the managed bean and opens a Java editor to the location of the code. An example of converter code created for an input control is shown here:
public javax.faces.convert.Converter getInputID_converter()
{
return new javax.faces.convert.Converter()
{
/**
* Convert the input Object into a string.
*/
public String getAsString( javax.faces.context.FacesContext context,
javax.faces.component.UIComponent component, java.lang.Object value)
{
// TODO: Convert the Object to a String here.
return value.toString();
}
/**
* Convert the input String into an Object.
*/
public Object getAsObject( javax.faces.context.FacesContext context,
javax.faces.component.UIComponent component, java.lang.String value)
{
// TODO: Convert the String to an Object here.
return "New Object: "+ value;
}
};
}
5. After the TODO comments, type the Java code required for the converter.
Related Topics