Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JSF binding conversion

 
Georgian Micsa
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • 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
 
Tim Holloway
Saloon Keeper
Pie
Posts: 18012
47
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • 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
  • 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
 
Bauke Scholtz
Ranch Hand
Posts: 2458
  • Mark post as helpful
  • send pies
  • 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
Pie
Posts: 18012
47
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • 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!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic