rynmrtn
rynmrtn

Reputation: 3419

Dynamic Chart generation / Pass object to Servlet from JSF 1.2

I am attempting to dynamically generate charts using the JFreeChart library and display them to a user on the front-end. My project is using JSF 1.2 as its view technology and we are trying to determine a strategy to display a BufferedImage.

Thus far, the best option seems to be to generate the graph using a servlet and use h:graphicImage to point to that location. The primary question is, how can I pass an object from JSF to the servlet so that the graph generation is dynamic based on the values in the object?

Upvotes: 4

Views: 1671

Answers (2)

BalusC
BalusC

Reputation: 1108722

Let JSF put it in session along an autogenerated and unique key, pass that key as request parameter or pathinfo to the servlet and finally let the servlet remove it from the session by the key and use it.

JSF bean (during init or action method):

this.key = UUID.randomUUID().toString();
externalContext.getSessionMap().put(key, object);

JSF view:

<h:graphicImage value="servleturl?key=#{bean.key}" />

Servlet:

String key = request.getParameter("key");
Object object = request.getSession().getAttribute(key);
request.getSession().removeAttribute(key);
// ...

Upvotes: 4

McDowell
McDowell

Reputation: 108899

Personally, I would prefer to pass the data as part of the URL as this avoids relying on server state and makes the chart service easier to externalize. However, you may run into some practical limitations if your data set is large.

Upvotes: 2

Related Questions