Add your own converter in RichFaces


First, you may create class “MyConverter.java” for example, this class must implements Converter with two methods.

package my.converter;

import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;

public class MyConverter implements Converter {

	public MyConverter() {
	}

	@Override
	public Object getAsObject(FacesContext arg0, UIComponent arg1, String arg2) {
		return (Object)arg2;
	}

	@Override
	public String getAsString(FacesContext arg0, UIComponent arg1, Object arg2) {
		return arg2.toString();
	}
}

Second, add your converter to your faces-config.xml.

<converter>
    <converter-id>MyConverter</converter-id>
    <converter-class>my.converter.MyConverter</converter-class>
</converter>

Third, add MyConverter.class in WEB-INF/classes/ in your War file.

To finish use it in your xhtml with the tag :

<f:converter converterId="MyConverter" />
  1. No comments yet.
(will not be published)
  1. No trackbacks yet.