Mike, how I do this for Cayenne is to add a special string to
represent null (and another one to represent disabled). The converter
then renders the special string for null and decodes the special
string to null. All converters are code-generated from my model (same
with the faces-config*.xml file that registers them).
<h:selectOneMenu
value="#{page.item}">
<f:selectItem
itemValue="#{page.nullSelectItemOptionValue}"
itemLabel="<No selection>" />
<f:selectItems .../>
</h:selectOneMenu>
public Object getAsObject(FacesContext context, UIComponent
component, String value) throws ConverterException
{
if (null == value) return null;
if (ConverterOptions.DISABLED_OPTION_VALUE.equals(value)) return null;
if (ConverterOptions.NULL_OPTION_VALUE.equals(value)) return null;
return findItemByIDString(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 findIDStringByItem((Item)value);
}
On 4/17/07, Mike Quilleash <[EMAIL PROTECTED]> wrote:
Hi all,
I have a selectOneMenu where the value is set to a many-to-one property in a
hibernate entity
<h:selectOneMenu value="#{hibObj.otherObj}" required="true">
and
class HibObj
{
public OtherObj getOtherObj() { ... }
}
Initially otherObj is set to null. I generate a select item list for
possible values of otherObj preceeded by a "Please Select" item that should
be the initial selection. The SelectItem for the no selection has it's
value set to null, label of "Please Select", and disabled set to true.
However when the menu renders it displays the first item after the "Please
Select". Debugging in the code shows that the null, both in the SelectItem
and returned when value is evaluated, are special cases and get converted to
empty strings or cause the matching to be skipped altogether. (I then think
the browser defaults to selecting the first non-disabled item as the html
selected is not against any of the options).
Does anyone have any ideas how to get this to work? I'm happy enough to put
a null placeholder in the Please Select Item but I don't want to/can't do
that in the hibernate model.
Any help or suggestions appreciated.
Cheers.
Mike.
This e-mail is bound by the terms and conditions described at
http://www.subexazure.com/mail-disclaimer.html