Hi all,

I'm creating a custom converter in order to use smallint database fields with
boolean components, such as SelectBooleanCheckBox. I'm doing this because
Firebird SQL doesn't have a real boolean type.

I've written a very simple converter:

package frautils.Converters;

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

public class intBoolConverter implements Converter {
  public static final String CONVERTER_ID ="intBoolConverter";

  public Object getAsObject(FacesContext context, UIComponent component,
                            String newValue) throws ConverterException {
      return (newValue.equals("1");

  }
  public String getAsString(FacesContext context, UIComponent component,
                            Object value) throws ConverterException {
    String s = "0";
    if (value.toString().equals("true")) { s = "1"; };
    return s;
  }

...and I've registered this in faces-config.xml:


<converter> <converter-id>intBoolConverter</converter-id> <converter-class>frautils.Converters.intBoolConverter</converter-class> </converter>

..and I'm using that in this way:

  <h:selectBooleanCheckbox value="#{lista.FRUITO}">
     <f:converter converterId="intBoolConverter"/>
  </h:selectBooleanCheckbox>

("FRUITO" is a smallint field )
the problem is that the converter class is never being called, and the
application returns this error:

java.lang.ClassCastException: java.lang.Integer
at javax.faces.component.UISelectBoolean.isSelected(UISelectBoolean.java:38)
at
net.sourceforge.myfaces.renderkit.html.HtmlCheckboxRendererBase.encodeEnd(HtmlCheckboxRendererBase.java:84)
...etc.......



where am I wrong ?

thanks,



--
Francesco Consumi
Ufficio Sistemi informativi
Istituto degli Innocenti
Piazza SS.Annunziata, 12
50122 Firenze
consumi at istitutodeglinnocenti.it
Tel. +39 055 2037320
ICQ# 12516133



Reply via email to