• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Return null from a Converter?

 
Ranch Hand
Posts: 108
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I've written a custom converter but I'm having a problem setting a null/empty value with it. If a user inputs a value, such as "123abc", into an inputText and the value is applied through a submit or an ajax call and then later that value is deleted from the inputText by the user, the old value, "123abc", remains upon the next submit or ajax call. The behavior I want is for that property bound to the value of the inputText to be set to null. In my converter in getAsObject() I am returning null if the incoming String has a length of zero and that seems to be the issue. But since the property classtype may be java.util.Date I don't want to try and assign an empty String to it. Any ideas?
 
Rob Micah
Ranch Hand
Posts: 108
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It seems that returning null from getAsObject() causes no decoding to be done on the request value. I have looked but can't find that behavior documented anywhere. Can anybody confirm this?
 
Saloon Keeper
Posts: 27763
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I can't point you to any specific documentation, but yes, JSF, like HTML, is quite averse to NULL data. And I can tell you from painful experience that NULL values in databases can be only slightly less injurious to one's sanity than attempting to use dates as database keys.

I prefer Calendar date controls like many extension tagsets offer anyway. If I had a date item and really truly wanted it to be nullable, I'd generally use a façade property on the backing bean and use that to populate the nullable persistent property that it corresponded to. I would then handle the null values as part of the general store/fetch code for that property.
 
Rob Micah
Ranch Hand
Posts: 108
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I've been thinking about creating all my properties as Strings on the backend. One of the reasons is it makes it easier to get some AJAX working because my converters are throwing exceptions. But what kind of problems or headaches would I have if I did this? I would have to move my validation to a separate method and call it somehow upon submission. Am I asking for trouble with that approach?
 
reply
    Bookmark Topic Watch Topic
  • New Topic