File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » JSF
Bookmark "Javascript call bean setter" Watch "Javascript call bean setter" New topic
Author

Javascript call bean setter

victor bernado
Greenhorn

Joined: Mar 21, 2012
Posts: 1
Hi,

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:


Thanks
VĂ­ctor
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16305
    
  21

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.


Customer surveys are for companies who didn't pay proper attention to begin with.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Javascript call bean setter