• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Return null from a Converter?

 
Rob Micah
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
  • 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: 98
  • Mark post as helpful
  • send pies
  • 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?
 
Tim Holloway
Saloon Keeper
Pie
Posts: 18212
53
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • 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: 98
  • Mark post as helpful
  • send pies
  • 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?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic