aspose file tools*
The moose likes JSF and the fly likes JSF binding conversion Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSF
Bookmark "JSF binding conversion" Watch "JSF binding conversion" New topic
Author

JSF binding conversion

Georgian Micsa
Greenhorn

Joined: Mar 15, 2009
Posts: 4
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

Joined: Jun 25, 2001
Posts: 16246
    
  21

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.


Customer surveys are for companies who didn't pay proper attention to begin with.
Georgian Micsa
Greenhorn

Joined: Mar 15, 2009
Posts: 4
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

Joined: Oct 08, 2006
Posts: 2458
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

Joined: Jun 25, 2001
Posts: 16246
    
  21

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!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JSF binding conversion