You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@myfaces.apache.org by Rafael Nami <ra...@gmail.com> on 2006/04/11 23:39:50 UTC

Empty h:inputText field is being submitted with "" value - Is that right???

Well, good evening everyone (here in Brazil is 18:30).
I'm developing a web application using the Spring/Hibernate/JSF-MyFaces
combo, and so far is being a silver bullet to me.
Well, I have several search forms in my webapp, but when I submit a empty
inputText, the value passed to the backing bean is the "" value, and this is
directly impacting in my backend, because I'm using Hibernate Criteria API
for the search method. Is this "conversion" the right behavior? If it is,
how can I convert this value to null??

Thanks in advance

Rafael Mauricio Nami

Re: Empty h:inputText field is being submitted with "" value - Is that right???

Posted by Rafael Nami <ra...@gmail.com>.
Thanks Mike, I've done a workaround quite similar using Reflection on my DAO
base class to populate a Criteria Object with my filter. I think there's a
more elegant way to do this using Hibernate's PropertyResolver, but I'll
switch to this in the next refactoring.

Best Regards

Rafael Mauricio Nami


2006/4/11, Mike Kienenberger <mk...@gmail.com>:
>
> On 4/11/06, Rafael Nami <ra...@gmail.com> wrote:
> > when I submit a empty
> > inputText, the value passed to the backing bean is the "" value, and
> this is
> > directly impacting in my backend, because I'm using Hibernate Criteria
> API
> > for the search method. Is this "conversion" the right behavior? If it
> is,
> > how can I convert this value to null??
>
> In JSF 1.2, you will be able to register a StringConverter to change
> the values from "" to null.
>
> For now, you have to handle this in your backend code.   Not sure how
> it's done for Hibernate, but for Cayenne, I have a method that does
> this on the BaseDataObject superclass for all of my entity classes.
> There's probably a way to do something similar in Hibernate.
>
>    public void writeProperty(String propName, Object value)
>    {
>        // Oracle can't handle empty strings, and JSF generates them
> instead of nulls.
>        if ( (value instanceof String) && (0 == ((String)value).length()) )
>            super.writeProperty(propName, null);
>        else super.writeProperty(propName, value);
>    }
>

Re: Empty h:inputText field is being submitted with "" value - Is that right???

Posted by Mike Kienenberger <mk...@gmail.com>.
On 4/11/06, Rafael Nami <ra...@gmail.com> wrote:
> when I submit a empty
> inputText, the value passed to the backing bean is the "" value, and this is
> directly impacting in my backend, because I'm using Hibernate Criteria API
> for the search method. Is this "conversion" the right behavior? If it is,
> how can I convert this value to null??

In JSF 1.2, you will be able to register a StringConverter to change
the values from "" to null.

For now, you have to handle this in your backend code.   Not sure how
it's done for Hibernate, but for Cayenne, I have a method that does
this on the BaseDataObject superclass for all of my entity classes.  
There's probably a way to do something similar in Hibernate.

    public void writeProperty(String propName, Object value)
    {
        // Oracle can't handle empty strings, and JSF generates them
instead of nulls.
        if ( (value instanceof String) && (0 == ((String)value).length()) )
            super.writeProperty(propName, null);
        else super.writeProperty(propName, value);
    }