Hi

If u where to use Hibernate, it handles this excelently - I use it
against Adaptive Server Anywhere. It neither has a boolean value, and I
use tinyint instead.

Hermod

-----Opprinnelig melding-----
Fra: Francesco Consumi [mailto:[EMAIL PROTECTED]
Sendt: 7. desember 2004 11:55
Til: [EMAIL PROTECTED]
Emne: boolean custom converter


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.encodeEn
d(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


* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

This email with attachments is solely for the use of the individual or
entity to whom it is addressed. Please also be aware that the DnB NOR Group
cannot accept any payment orders or other legally binding correspondence with
customers as a part of an email. 

This email message has been virus checked by the virus programs used
in the DnB NOR Group.

* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

Reply via email to