• Post Reply Bookmark Topic Watch Topic
  • New Topic

converter on output text ? Cannot cast String to date  RSS feed

 
Cedric Bosch
Ranch Hand
Posts: 99
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is this possible ? I'm assuming when I call the converter on an outputText the util.Date in the value attribute has been through toString. Ence why I get an exception cannot cast From String to Date. Is there a workaround to this ?



with in the converter :



Is there a workaround that keeps the utility of converters or should I just do it like this ? :

 
Tim Holloway
Bartender
Posts: 18715
71
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I had to think about that one. Your value isn't a simple conversion. Consider this one:

On July 21, 3087 there were 14.337 vatsnors per snarlg by it increased by 0.32 vatsnors on Jul 22.

Here, we'd had to have 2 different types of conversion - one for the float/double, one for the date. And they're not even all using the same rules - different date formats, different decimal precisions.

JSF's converters are primarily designed to convert input control values to and from HTML text form, and their use as output-only converters is more of a side-effect. And one that I suspect is limited to simple values. So this should work:



In othe words, remove the spaces from the value expression and output them separately. But don't forget that HTML collapses multiple spaces down. To actually render with multiple spaces, you'd either have to use the   entity (not recommended) or use CSS. For example:



Which should give you a left pad of the width of 2 letter "m"s. If it doesn't wrap the whole thing in a styled HTML div or JSF 1-column h:panelGrid.

If you still get conversion errors, it's probable that you did what I always do and wrote the converter with the input and output functions swapped.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!