开发者

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 str开发者_JS百科ategy 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?


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);
// ...


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜