Many JavaScript widgets expect data and options in JSON format. Nowadays, it is really easy to choose a cool widget and wrap it in a composite component. But the first question is how to send an AJAX request and to recieve a
response in a proper JSON format. This question is often raised by JSF users. All that you need is a XHTML facelet like this one:
Please consider the contentType=”text/html” (application/json will not work here) and escape=”false” in the hutputText. The method getClosestStations() in the bean StationView produces an JSON output for a list of special Java
objects. I advise to use the Gson library in order to serialize any Java object to JSON. Short example: