File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JSF and the fly likes Javascript call bean setter Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSF
Bookmark "Javascript call bean setter" Watch "Javascript call bean setter" New topic

Javascript call bean setter

victor bernado

Joined: Mar 21, 2012
Posts: 1

I'm trying to develop a mobile application with JSF2 and PrimeFaces.
At home page I have a GoogleMap and a JavaScript that find the current location and locate it at the map:

I have a GeoLocationBean that hold latitude and longitude, and I want that when findMe() has been executed call the geolocationBean.setLatitude( long ) and geolocationBean.setLongitude( long ) method.
There are any way to do it throw javascript?

A solution that I found (but it doesn't work) is:
- javascript update a hide element that hold latitude
- the hide element has an f:ajax that when valuechanged occurs, call setLatitude.
but valuechanged occurs only if user type in the inputtext

the complet index.xhtml file is:

Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 17417

The only way to get javascript to read or write to a server-side object (JSF backing bean) is to use AJAX. JavaScript runs only on the client, so the backing bean and the script reside on separate computers.
An "onclick" handler should end with a "return true" or "return false" in order to tell the control whether it should submit the form after it has run the findMe() js function.

You should be able to retrieve the form's current latitude value by locating the DOM object whose ID is "latitude". Normally it would be "formid:latitude", but you switched off the form's prependid attribute. Longitude, of course, follows the same strategy.

An IDE is no substitute for an Intelligent Developer.
I agree. Here's the link:
subject: Javascript call bean setter
jQuery in Action, 3rd edition