users@glassfish.java.net

Custom Boolean Converted worked fine with GF3.0.1+JSF1.2 and now it doesn't

From: <forums_at_java.net>
Date: Fri, 29 Apr 2011 14:34:25 -0500 (CDT)

Hi,

Environment: NetBeans 7.0 + GlassFish 3.1 + JSF 2.0 + CDI/Weld 1.1.0.

Previous environment that worked: NetBeans 6.9.1 + GlassFish 3.0.1 + JSF 1.2
+ CDI/Weld 1.0.0.

I have used selectBooleanCheckbox with a custom converter
"snBooleanConverter", where N = false and S = true, getting data from a
legacy database that save the field "acessar" using a CHAR(1) datatype. This
is a sample of the component:

[code]

<h:selectBooleanCheckbox id="acessar" value="#{bean.acessar}"><f:converter
converterId="snBooleanConverter"/></h:selectBooleanCheckbox>

[/code]

The converter is below:

[code]

package SubMacroWeb.convert;

import javax.faces.component.UIComponent;

import javax.faces.context.FacesContext;

import javax.faces.convert.Converter;

import javax.faces.convert.FacesConverter;

@FacesConverter(value="snBooleanConverter")

public class SNBooleanConverter implements Converter {

  public SNBooleanConverter() {}

  @Override

  public Object getAsObject(FacesContext facesContext, UIComponent
uiComponent, String string) {

    if (string == null) {

      return "N";

    }

    try {

      if (!Boolean.parseBoolean(string))

        return "N";

      else

        return "S";

    } catch (Exception e) {

      e.printStackTrace();

      return null;

    }

  }

  @Override

  public String getAsString(FacesContext facesContext, UIComponent
uIComponent, Object object) {

    if (object == null) {

      return "N";

    }

    try {

      Boolean ret = object.toString().equals("S");

      return ret.toString();

    } catch (Exception e) {

      throw new IllegalArgumentException("object:" + object + " of
type:" + object.getClass().getName() + "; expected type: Boolean");

    }

  }

}

[/code]

The faces-config.xhtml has this config:

[code]

  <converter>

    <converter-id>snBooleanConverter</converter-id>

   
<converter-class>SubMacroWeb.convert.SNBooleanConverter</converter-class>

  </converter>

[/code]

Before using JSF1.2 the getAsString method received an object "String", with
value S or N.

Now using JSF2.0 the getAsString method receives an object "Boolean", and
always is false. I think the JSF2.0 doesn't understand the values S or N, and
always returns false.


--
[Message sent by forum member 'edilmar']
View Post: http://forums.java.net/node/796983