Saturday, January 16, 2010

NetBeans JSF Converter Template

Object conversion is a common requirement in JSF. Surprisingly there is no template for a JSF Converter in the NetBeans Template list. I have created a template to create JSF Converters in NetBeans.

To use the template is very simple:

  1. Download the template.
  2. Start NetBeans.
  3. Go to Tools --> Templates.
  4. Select the JavaServer Faces folder.
  5. Select Add from the menu.
  6. Locate the file you downloaded and select it, and you are done.

Here is the file:

<#assign licenseFirst = "/*">
<#assign licensePrefix = " * ">
<#assign licenseLast = " */">
<#include "../Licenses/license-${project.license}.txt">

<#if package?? && package !="">
package ${package};

import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;
 * @author ${user}

public class ${name} implements Converter{

    public Object getAsObject(FacesContext facesContext, UIComponent component, String value) {
        throw new UnsupportedOperationException("Not supported yet.");

public String getAsString(FacesContext facesContext, UIComponent component, Object value) {
        throw new UnsupportedOperationException("Not supported yet.");


Popular Posts