You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@myfaces.apache.org by Mike Quilleash <mi...@subexazure.com> on 2007/04/17 14:00:21 UTC

Nulls and hibernate objects

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


RE: Nulls and hibernate objects

Posted by Mike Quilleash <mi...@subexazure.com>.
Thanks for the reply.
 
I'm not sure converters work here because they are only used when
actually converting an object to a string for HTML output or converting
a form submission back to an object.
 
The part I think I am falling down on is where it tries to equate the
current server value of the menu (null) to one of the select item values
(one of which is null).  However it seems that nulls are treated
specially or ignored somehow, the result being the "selected" attribute
never gets put on my "Please Select" item during the rendering of the
HTML <option>.  I have not got as far as form submission yet, this is
just a rendering problem.
 
Mike.

________________________________

From: Strittmatter, Stephan [mailto:Stephan.Strittmatter@sybit.de] 
Sent: 17 April 2007 13:04
To: MyFaces Discussion
Subject: RE: Nulls and hibernate objects


Hi Mike,
 
probably this will focus to the right direction:
http://jroller.com/page/stritti?entry=jsf_stringconverter_for_null_value
s
 
Regards,
 
Stephan

________________________________

From: Mike Quilleash [mailto:mike.quilleash@subexazure.com] 
Sent: Tuesday, April 17, 2007 2:00 PM
To: MyFaces Discussion
Subject: Nulls and hibernate objects


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


 This e-mail is bound by the terms and conditions described at http://www.subexazure.com/mail-disclaimer.html


RE: Nulls and hibernate objects

Posted by "Strittmatter, Stephan" <St...@sybit.de>.
Hi Mike,
 
probably this will focus to the right direction:
http://jroller.com/page/stritti?entry=jsf_stringconverter_for_null_value
s
 
Regards,
 
Stephan

________________________________

From: Mike Quilleash [mailto:mike.quilleash@subexazure.com] 
Sent: Tuesday, April 17, 2007 2:00 PM
To: MyFaces Discussion
Subject: Nulls and hibernate objects


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


Re: Nulls and hibernate objects

Posted by Mike Kienenberger <mk...@gmail.com>.
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="&lt;No selection&gt;" />
        <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 <mi...@subexazure.com> 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
>
>
>