I need to render an HTML table from a Servlet, in response to an AJAX request. I’m wondering what the best way to go about this is? I’ve explored using an javax.faces.component.html.HtmlDataTable. One of the questions I have regarding this method is how to render the HTML once the table has been populated. From the looks of it, a FacesContext is required.
Any ideas?
JSF isn’t what you’re looking for. It’s a component based MVC framework. Just do it either the easy and ugly way in a simple loop in the servlet:
Or store it as request attribute and forward to a JSP
Which in turn basically contains the following:
Or rather look for a different and more flexible data format like JSON so that the client has the freedom how to render it. Here’s an example which uses Google Gson.
Which you can render into a table using jQuery as follows:
See also: