从JSF 1.2生成动态图表/将对象传递给Servlet [英] Dynamic Chart generation / Pass object to Servlet from JSF 1.2

查看:89
本文介绍了从JSF 1.2生成动态图表/将对象传递给Servlet的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用JFreeChart库动态生成图表,并将它们显示给前端的用户。我的项目使用JSF 1.2作为其视图技术,我们正在尝试确定显示 BufferedImage 的策略。

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.

到目前为止,最好的选择似乎是使用servlet生成图形并使用 h:graphicImage 来指向那个位置。主要问题是,如何将对象从JSF传递给servlet,以便根据对象中的值生成图形?

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?

推荐答案

让JSF沿着自动生成的唯一键将其放入会话中,将该键作为请求参数或pathinfo传递给servlet,最后让servlet通过密钥将其从会话中删除并使用它。

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(在init或action方法期间):

JSF bean (during init or action method):

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

JSF查看:

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

Servlet:

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

这篇关于从JSF 1.2生成动态图表/将对象传递给Servlet的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆