Generating a Dynamic Chart / Passing an Object to a Servlet from JSF 1.2

I am trying to dynamically generate charts using the JFreeChart library and display them for the user on the interface. My project uses JSF 1.2 as a viewing technology, and we are trying to define a BufferedImage display strategy.

So far, the best option seems to have been to create a graph using a servlet and use h:graphicImage to point to this location. The main question is: how can I pass an object from JSF to a servlet so that the graph generation is dynamic based on the values ​​in the object?

+4
source share
2 answers

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

JSF bean (during initialization or action):

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

Personally, I would prefer to transfer data as part of the URL, as this avoids depending on the state of the server and simplifies the work with the graphic service. However, you may encounter some practical limitations if your data set is large.

+2
source

Source: https://habr.com/ru/post/1334445/


All Articles