This discussion is archived
2 Replies Latest reply: Apr 27, 2012 8:00 AM by 933646 RSS

How to invoke javascript after getting a value from backing bean

933646 Newbie
Currently Being Moderated
I am developing a functionality in my jsf application, which should retrieve the lat and lon of places from the database and plot it in Google map. Since gmaps4jsf library is not updated with google maps java script api v3, i'm using google maps java script api v3.

My requirement is that two actions has to be performed when the user clicks a button.
1. Lat and Lon value needs to be retrieved from back end(preferably using jsf) .
2. The retrieved value then has to be used to plot the location in map using java script.

The problem is that I can't call the script to plot the place in map after retrieving the lat and lon.

What is the solution to this problem?

Regards,
Arun

Edited by: 930643 on Apr 27, 2012 12:40 AM
  • 1. Re: How to invoke javascript after getting a value from backing bean
    gimbal2 Guru
    Currently Being Moderated
    The trouble is that JSF is a server side API and you are working with client side APIs here. What client side support JSF has (in ways of Ajax), it is built to actually support the server side, not primarily the client side.

    In this case I don't think you need JSF or will have a benefit from JSF to fulfill your requirement. I would create something like a servlet which can be invoked through Ajax (use JQuery for example) to fetch the data in an easy to work with format, like JSON (Google GSON API works really well to translate Java beans to JSON data). That way you can keep all the actual application logic stuff client side javascript.
  • 2. Re: How to invoke javascript after getting a value from backing bean
    933646 Newbie
    Currently Being Moderated
    Thanks for your input. I was looking for a solution in JSF and I got it. It's achieved by rendering an h:outputScript after getting value from backing bean.

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points