You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Alexander Hartner <al...@j2anywhere.com> on 2008/10/19 22:04:49 UTC
Using Convert to handle NULL values for empty Strings ""
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
Re: Using Convert to handle NULL values for empty Strings ""
Posted by Mark Thomas <ma...@apache.org>.
Alexander Hartner wrote:
> Setting the COERCE_TO_ZERO to false in 6.0.18 did the trick for me.
Just a word of warning. Setting COERCE_TO_ZERO to false is not spec
compliant. If you switch containers then you may see different behaviour.
Mark
> Initially I only tested this on 6.0.16.
>
> Thanks Chuck.
> On 20 Oct 2008, at 00:12, Alexander Hartner wrote:
>
>> Hi Chuck,
>>
>> Thanks for coming back to me to quickly. I have tried this, but this
>> only seems to work for numbers. I am looking at Strings.
>>
>> So far I have tested this with Sun's JSF 1.2_04-b20-p03 as well as
>> 1.2_09-b02-FCS and myfaces-core-1.2.4.
>>
>> MyFaces gave me some other errors, but now behaves in exactly the same
>> way at Sun implementation, converting any nulls returned by the
>> converter into an empty string.
>>
>> I am hoping that there is a simple solution for this as I surely can't
>> be the first one to pick this up.
>>
>> Thanks for all your support.
>> Alex
>>
>>
>> On 19 Oct 2008, at 23:41, Caldarale, Charles R wrote:
>>
>>>> From: Alexander Hartner [mailto:alex@j2anywhere.com]
>>>> Subject: Re: Using Convert to handle NULL values for empty Strings ""
>>>>
>>>> The problem indeed does not appear in 6.0.14, however both
>>>> 6.0.16 and 18 are affected by it.
>>>>
>>>> I wonder what has changed, and how I can fix this
>>>
>>> This might be related:
>>> https://issues.apache.org/bugzilla/show_bug.cgi?id=43285
>>>
>>> Try playing with the associated COERCE_TO_ZERO system property to see
>>> if it has an effect:
>>> http://tomcat.apache.org/tomcat-6.0-doc/config/systemprops.html#Expression%20Language
>>>
>>>
>>> - Chuck
>>>
>>>
>>> THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE
>>> PROPRIETARY MATERIAL and is thus for use only by the intended
>>> recipient. If you received this in error, please contact the sender
>>> and delete the e-mail and its attachments from all computers.
>>>
>>> ---------------------------------------------------------------------
>>> To start a new topic, e-mail: users@tomcat.apache.org
>>> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
>>> For additional commands, e-mail: users-help@tomcat.apache.org
>>>
>>
>
>
> ---------------------------------------------------------------------
> To start a new topic, e-mail: users@tomcat.apache.org
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
>
---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
Re: Using Convert to handle NULL values for empty Strings ""
Posted by Alexander Hartner <al...@j2anywhere.com>.
Setting the COERCE_TO_ZERO to false in 6.0.18 did the trick for me.
Initially I only tested this on 6.0.16.
Thanks Chuck.
On 20 Oct 2008, at 00:12, Alexander Hartner wrote:
> Hi Chuck,
>
> Thanks for coming back to me to quickly. I have tried this, but this
> only seems to work for numbers. I am looking at Strings.
>
> So far I have tested this with Sun's JSF 1.2_04-b20-p03 as well as
> 1.2_09-b02-FCS and myfaces-core-1.2.4.
>
> MyFaces gave me some other errors, but now behaves in exactly the
> same way at Sun implementation, converting any nulls returned by the
> converter into an empty string.
>
> I am hoping that there is a simple solution for this as I surely
> can't be the first one to pick this up.
>
> Thanks for all your support.
> Alex
>
>
> On 19 Oct 2008, at 23:41, Caldarale, Charles R wrote:
>
>>> From: Alexander Hartner [mailto:alex@j2anywhere.com]
>>> Subject: Re: Using Convert to handle NULL values for empty Strings
>>> ""
>>>
>>> The problem indeed does not appear in 6.0.14, however both
>>> 6.0.16 and 18 are affected by it.
>>>
>>> I wonder what has changed, and how I can fix this
>>
>> This might be related:
>> https://issues.apache.org/bugzilla/show_bug.cgi?id=43285
>>
>> Try playing with the associated COERCE_TO_ZERO system property to
>> see if it has an effect:
>> http://tomcat.apache.org/tomcat-6.0-doc/config/systemprops.html#Expression%20Language
>>
>> - Chuck
>>
>>
>> THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE
>> PROPRIETARY MATERIAL and is thus for use only by the intended
>> recipient. If you received this in error, please contact the sender
>> and delete the e-mail and its attachments from all computers.
>>
>> ---------------------------------------------------------------------
>> To start a new topic, e-mail: users@tomcat.apache.org
>> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
>> For additional commands, e-mail: users-help@tomcat.apache.org
>>
>
---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
Re: Using Convert to handle NULL values for empty Strings ""
Posted by Alexander Hartner <al...@j2anywhere.com>.
Hi Chuck,
Thanks for coming back to me to quickly. I have tried this, but this
only seems to work for numbers. I am looking at Strings.
So far I have tested this with Sun's JSF 1.2_04-b20-p03 as well as
1.2_09-b02-FCS and myfaces-core-1.2.4.
MyFaces gave me some other errors, but now behaves in exactly the same
way at Sun implementation, converting any nulls returned by the
converter into an empty string.
I am hoping that there is a simple solution for this as I surely can't
be the first one to pick this up.
Thanks for all your support.
Alex
On 19 Oct 2008, at 23:41, Caldarale, Charles R wrote:
>> From: Alexander Hartner [mailto:alex@j2anywhere.com]
>> Subject: Re: Using Convert to handle NULL values for empty Strings ""
>>
>> The problem indeed does not appear in 6.0.14, however both
>> 6.0.16 and 18 are affected by it.
>>
>> I wonder what has changed, and how I can fix this
>
> This might be related:
> https://issues.apache.org/bugzilla/show_bug.cgi?id=43285
>
> Try playing with the associated COERCE_TO_ZERO system property to
> see if it has an effect:
> http://tomcat.apache.org/tomcat-6.0-doc/config/systemprops.html#Expression%20Language
>
> - Chuck
>
>
> THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE
> PROPRIETARY MATERIAL and is thus for use only by the intended
> recipient. If you received this in error, please contact the sender
> and delete the e-mail and its attachments from all computers.
>
> ---------------------------------------------------------------------
> To start a new topic, e-mail: users@tomcat.apache.org
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
RE: Using Convert to handle NULL values for empty Strings ""
Posted by "Caldarale, Charles R" <Ch...@unisys.com>.
> From: Alexander Hartner [mailto:alex@j2anywhere.com]
> Subject: Re: Using Convert to handle NULL values for empty Strings ""
>
> The problem indeed does not appear in 6.0.14, however both
> 6.0.16 and 18 are affected by it.
>
> I wonder what has changed, and how I can fix this
This might be related:
https://issues.apache.org/bugzilla/show_bug.cgi?id=43285
Try playing with the associated COERCE_TO_ZERO system property to see if it has an effect:
http://tomcat.apache.org/tomcat-6.0-doc/config/systemprops.html#Expression%20Language
- Chuck
THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY MATERIAL and is thus for use only by the intended recipient. If you received this in error, please contact the sender and delete the e-mail and its attachments from all computers.
---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
Re: Using Convert to handle NULL values for empty Strings ""
Posted by Alexander Hartner <al...@j2anywhere.com>.
This problems seems to be related to the version of tomcat being used:
I came accross this post online :
http://forums.sun.com/thread.jspa?forumID=427&threadID=5273588
and then tried 6.0.18 and 6.0.14. Previously I was using 6.0.16. The
problem indeed does not appear in 6.0.14, however both 6.0.16 and 18
are affected by it.
I found some other posts on this issue as well :
http://www.icefaces.org/JForum/posts/list/8024.page and https://issues.apache.org/jira/browse/MYFACES-1979
I wonder what has changed, and how I can fix this
Alex
On 19 Oct 2008, at 21:04, Alexander Hartner wrote:
> 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
---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org