我需要在网格布局中的grails页面上显示四个图表,位置为11,12,21和22.每个图表都使用类似于以下代码构建:
<img src="${createLink(controller:'paretoChart', action:'buildParetoChart11')}"/>
图表构建操作的代码是:
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)返回OutputStream中图表的BufferedImage,但它仅适用于一个图表。其他三个图表因每个所有浇筑操作的顺序而异。
PlotService是我写的,是的。在这个实现中,我将OutputStream从response.outputStream和String idPOvalue传递给Java方法。 plotPareto的实现如下:
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);
}
那么,有没有办法确保一个动作在启动下一个动作之前完成?
提前致谢!
答案 0 :(得分:1)
每个获取图像的请求都由浏览器异步处理。每个请求都在服务器上的自己的线程中运行。使用img标签,浏览器控制GET请求以获取图像,因此我认为您不能轻易保证订单,也不应该这样做。
您是否看到任何错误?
我会查看firebug或等效输出,看看浏览器是否出错。对于任何图像请求。
我还会尝试将调试器附加到您的服务器上。
你写过PlotService了吗?您需要确保它是线程安全的。
另外,我没有看到你读过任何参数,每个图像都有单独的动作吗?