This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
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

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » JSF
Bookmark "JSF binding conversion" Watch "JSF binding conversion" New topic

JSF binding conversion

Georgian Micsa

Joined: Mar 15, 2009
Posts: 4

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?

Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 15959

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

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

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.

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: 15959

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 - he seems to have provided a rich set of examples.

Don't forget the GUnload(), BTW. Google maps leak when you do!
jQuery in Action, 2nd edition
subject: JSF binding conversion
Similar Threads
what is the differnet latitudeE6 and latitude
Measure distance between two cities ?
Javascript call bean setter
problem in java math function
Converting string to int