2011-09-13 58 views
0

我已将图像保存到命令对象中的一个字节[],并希望在createFlow webflow的下一个阶段显示它。Grails Webflow显示图像 - 流程范围

我试图避免在webflow期间使用文件系统和/或数据库系统来存储图像。然而

class ArtefactController { 

    def createFlow = { 
     ............ 
    } 

def renderImage = { 

    def ArtefactInstance = Artefact.findById(params.id) 
    if(ArtefactInstance?.image) { 
     response.setContentLength(ArtefactInstance.image.length) 
     response.outputStream.write(ArtefactInstance.image) 
    } 
    else { 
     response.sendError(404) 
    } 
} 

为Webflow的当尝试从GSP调用renderFlowImage:

典型地,观看图像,我称renderImage从GSP

def renderFlowImage = { 
    if(flow.artefactCommand?.image) { 
     response.setContentLength(flow.artefactCommand.image.length) 
     response.outputStream.write(flow.artefactCommand.image) 
    } 
    else { 
     response.sendError(404) 
    } 
} 

流量范围不可访问。

有什么建议吗?

回答

0

我假设你通过img标签打在你的流量与第二HTTP请求鉴于renderFlowImage操作,如:

<img src="${createLink(action:'renderFlowImage')}" /> 

这不会起作用,因为,一方面,你需要传入一个'flowExecutionKey',grails用来匹配一个请求和一个流。 解决这个问题是可能的,但是您可能会更好,只需在流的下一个视图的呈现阶段使用img标记中的数据URI呈现图像即可。您可以使用渲染插件轻松完成此操作,该插件提供了一些便利的标签(以及其他内容),以使用数据uri渲染内嵌图像。 所以在接下来的流程视图,你可以更换一个调用现有的img标签渲染插件的“内联”标签中的一个:

<rendering:inlineJpeg bytes="${artefactCommand.image}" /> 

但要小心 - 有一些限制的数据URI方法注意(见http://www.7cynics.com/webdesign/css/css-inline-images-data-uri.html)。

+0

感谢您的回应,这很好。 您是否知道我将如何解决flowExecutionKey的解决方法? – user898100

+0

对于解决方法,我想你可能会适应以下文章中描述的技术:http://bit.ly/8NnO8v和http://bit.ly/9ApKP7。但是我个人不想用仅仅致力于渲染图像的步骤来污染我的流量。你也可以看看“Ajaxflow”插件。 –