If I recall, one of the constructors does allow you to inconsistently
pass in a null.
And in JSF 1.2, I just saw a change-request go through to allow nulls.

However, I use a flag value.

public interface ConverterOptions
{
   public final static String DISABLED_OPTION_VALUE =
"com.xyz.jsf.converter.DISABLED_OPTION_VALUE";
   public final static String NULL_OPTION_VALUE =
"com.xyz.jsf.converter.NULL_OPTION_VALUE";
}


In my pages,

                                <f:selectItem
itemValue="com.xyz.jsf.converter.NULL_OPTION_VALUE" itemLabel="<no
selection>" />


In my (auto-generated) converters,

   public Object getAsObject(FacesContext context, UIComponent
component, String value) throws ConverterException
   {
        if (null == value)  return null;
       if (ConverterOptions.DISABLED_OPTION_VALUE.equals(value))
return ConverterOptions.DISABLED_OPTION_VALUE;
       if (ConverterOptions.NULL_OPTION_VALUE.equals(value))  return null;

       return findProjectTypeByIDString(value);
   }

   public String getAsString(FacesContext context, UIComponent
component, Object value) throws ConverterException
   {
        if (null == value)  return null;
       if (ConverterOptions.DISABLED_OPTION_VALUE.equals(value))
return ConverterOptions.DISABLED_OPTION_VALUE;
       if (ConverterOptions.NULL_OPTION_VALUE.equals(value))  return
ConverterOptions.NULL_OPTION_VALUE;

       return findIDStringByProjectType((ProjectType)value);
   }


On 8/12/06, Laurie Harper <[EMAIL PROTECTED]> wrote:
How do I create an 'empty' SelectItem? I'd like to present a
selectOneChoice which allows the target model value to be set to 'null'.
But I can't create a 'null' SelectItem:

   SelectItems[] items = new SelectItems[] {
     new SelectItem(null, "(none)"),
     new SelectItem(1, "one"),
     ...
   };

The SelectItems constructor has an explicit check for a null value or
label. Short of inventing a 'flag' value for every option list and using
a custom converter to translate it back to 'null' during apply values,
how do I get an 'empty' item in my SelectItems array?

L.


Reply via email to