• 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
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

JSF binding conversion

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I use gmap4jsf to render some maps. I have something like this

<m:map latitude="#{city.latitude}"...

The problem is that the city latitude is a Double in my entity and gmap4jsf tag expects there a String.
Is there a nice way to convert the value to a string inside the EL expression?
The only solution that i found without changing the bean field type is adding a method
getLatitudeAsString in city object that returns the String converted value and then use "#{city.latitudeAsString}" in jsf.
Any ideeas?

Thanks
 
Saloon Keeper
Posts: 28100
198
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
Are you sure you're not making a problem where there isn't one? Since view definitions are in XML/HTML and only text (string) data is allowed in them, the EL processor automcatically handles string-to-xx and xx-to-string conversions.
 
Georgian Micsa
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, in fact it seems that gmaps4jsf expects there a String:

java.lang.ClassCastException: java.lang.Double cannot be cast to java.lang.String
com.googlecode.gmaps4jsf.component.map.Map.getLatitude(Map.java:67)
com.googlecode.gmaps4jsf.util.MapRendererUtil.renderMapUsingLatLng(MapRendererUtil.java:121)
com.googlecode.gmaps4jsf.util.MapRendererUtil.startEncodingMapScript(MapRendererUtil.java:171)
com.googlecode.gmaps4jsf.component.map.MapRenderer.startEncodingMapRendererWrapper(MapRenderer.java:117)
com.googlecode.gmaps4jsf.component.map.MapRenderer.startEncodingMapWorld(MapRenderer.java:188)
com.googlecode.gmaps4jsf.component.map.MapRenderer.encodeBegin(MapRenderer.java:225)
javax.faces.component.UIComponentBase.encodeBegin(UIComponentBase.java:809)

The question remains open: is there a more elegant way to pass a String value to that tag without modifying my entity field.
I assume that the latitude and longitude fields must remain Double in my bean.

Thanks
 
Ranch Hand
Posts: 2458
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
A double can in no way represent degrees, minutes and seconds. So I take the gmaps4jsf component for right.

Wrap your double getter by a string getter.
 
Tim Holloway
Saloon Keeper
Posts: 28100
198
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 wrote my own Google Map JSF control a while back before all the other ones came out, so I went back and looked at the source code, since this sounds like a problem I had, but it appears that my map control did the conversions internally.

There's something odd going on here. The stack trace indicates a failure GETTING data from the map control, Since you didn't write the map control, I don't know how you could alter the data type it returns short of modifying the original source code. I'm still uncertain why the EL processor isn't handling the conversion here, but the first thing I'd do is check the TLD to make sure that an expression is even valid for that attribute. If only constants are allowed, that would cause a failure.

An example usage I found looks like this:



It's not using binary values, the latitude and longitude are decimal strings. But they're constants, not EL expressions.

I trust you're familiar with the author's web site at http://www.jroller.com/HazemBlog/entry/gmaps4jsf_create_your_map_with - he seems to have provided a rich set of examples.

Don't forget the GUnload(), BTW. Google maps leak when you do!
 
bacon. tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic