How to use multiple with one OutputStream

I need to show four diagrams on the grails page in a grid layout with positions 11, 12, 21 and 22. Each diagram is built with code similar to:

<img src="${createLink(controller:'paretoChart', action:'buildParetoChart11')}"/> 

Chart action action code:

  def buildParetoChart11 = { def PlotService p11 = PlotService.getInstance() def poList = paretoChartService.getParetoidPO() def listCounter = 0 def idPO = poList[listCounter] idPO.toString() def String idPOvalue = idPO def out = response.outputStream out = p11.paretoPlot(out, idPOvalue) response.setContentType("image/jpg") session["idPOList11"] = poList } 

Java p11.paretoPlot (out, idPOvalue) returns a BufferedImage of a chart inside an OutputStream, but only works for one chart. The other three diagrams vary depending on the order in which each action is called.

PlotService was written by me, yes. In this implementation, I pass an OutputStream obtained from response.outputStream and String idPOvalue for the Java method. plotPareto is as follows:

 public OutputStream paretoPlot(OutputStream out, String po) throws IOException { chart = buildParetoChart(po);// here the chart is actually built bufferedImage = chart.createBufferedImage(350, 275); ChartUtilities.writeBufferedImageAsJPEG(out, bufferedImage); } 

So, is there a way to make sure that one action is completed before the next one starts?

Thanks in advance!

+4
source share
1 answer

Each image request is processed asynchronously by the browser. Each request is executed in its thread on the server. Using img tags, the browser manages GET requests for images, so I donโ€™t think you can easily guarantee an order, and you donโ€™t need it either.

Do you see errors?

I would look at firebug or equivalent output to see if the browser is getting an error. for any of the image requests.

I would also try connecting a debugger to your server.

Do you write PlotService? You must ensure that it is thread safe.

Also, I donโ€™t see you reading any parameters, is there a separate action for each image?

+1
source

All Articles