I am developing a web application and I use JSF and PrimeFaces frameworks and external Geo Map API.
The Map API gives me POI_id
when I clicked on a POI on the map. But it's not enough for me, I want to get information about POI from a servlet and display it in a pop-up window. (fields like address, name, phone number, etc.).
So, I need to send an HTTP request to the servlet in my managed bean when I click the POI on the map.
I can get poi_id
, but I cannot send this id to the backend managed bean, so getting the POI information does not seem possible.
How can I send poi_id
to my managed bean and handle the response to display in a popup window?
Just to add to Kishor's (halfway) answer, you need to have a to-be-updated component in your view (popup window as you call it) and ajax-update it after the request has been successfully completed.
You can use remote command to send the AJAX request with an extra parameter attached and ajax-update the JSF component responsible to be a popup window. Like so (for PrimeFaces 3.x):
with
The alternative to using a remote command is to have a hidden form with a hidden input that will be used to transmit the parameter to the backing bean, that could be separated from other beans to handle the retrieval of necessary information based on your
poi_id
:with
You can use PrimeFaces remote command component (
<p:remoteCommand>
).Add it to the view it in a following way:
And use it in Javascript like so:
or call it from an event handler like so:
If you additionally want to pass parameters to the server make a following call:
The listener could be like:
One of the comments asked to return a Value to Javascript.
Well in that case you can use Primeface's Request Context's execute() method to execute any javascript you want.