【问题标题】:Grails Webflow display image - flow scopeGrails Webflow 显示图像 - 流范围
【发布时间】:2012-03-01 18:56:11
【问题描述】:

我已将图像保存到命令对象中的 byte[] 中,并希望在 createFlow webflow 的下一阶段显示它。

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

通常,要查看图像,我会从 gsp 调用 renderImage:

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 时:

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

无法访问的流范围。

有什么建议吗?

【问题讨论】:

    标签: image grails scope spring-webflow


    【解决方案1】:

    我假设您在流程视图中使用第二个 http 请求通过 img 标签点击了 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)。

    【讨论】:

    • 感谢您的回复,这很棒。你知道我将如何解决 flowExecutionKey 的解决方法吗?
    • 对于解决方法,我认为您可能能够适应以下文章中描述的技术:bit.ly/8NnO8vbit.ly/9ApKP7。但我个人不想用一个专门用于渲染图像的步骤来污染我的流程。您还可以查看“Ajaxflow”插件。
    猜你喜欢
    • 2010-12-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-12-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多