After having had the problem with null values not being returned as nulls and reading some suggestion solution I added a converter to my application.

...
  <converter>
    <converter-id>NullStringConverter</converter-id>
    <converter-for-class>java.lang.String</converter-for-class>
<converter- class>com.j2anywhere.addressbookserver.web.NullStringConverter</ converter-class>
  </converter>
...


I then implemented it as follows:

...
public String getAsString(FacesContext context, UIComponent component, Object object)
  {
    System.out.println("Converting to String : "+object);

    if (object == null)
    {
      System.out.println("READING null");
      return "NULL";
    }
    else
    {
      if (((String)object).equals(""))
      {
        System.out.println("READING null (Second Check)");
        return null;
      }
      else
      {
        return object.toString();
      }
    }
  }

public Object getAsObject(FacesContext context, UIComponent component, String value)
  {
System.out.println("Converting to Object: "+value +"-"+value.trim().length());
    if (value.trim().length()==0 || value.equals("NULL"))
    {
      System.out.println("WRITING null");
      return null;
    }
    else
    {
      return value.toUpperCase();
    }
  }
...


I can see that it is converting my values, however the object to which the inputText fields are bound are still set to empty strings ""

<h:inputText size="50" value="#{addressBookController.contactDetails.information}" converter="NullStringConverter"/>


Also when reading the object values any nulls are already converted to empty strings before ariving at the converter. It seems that there is a default converter handling string values.

How can I resolve this problem as set nulls when the input value is an empty string other then checking every string in my class individually. I would really hate to pollute my object model with empty string tests.

Thanks in advance

Reply via email to