grails - Grails GSP显示正在计算处理时间的服务变量

标签 grails service gsp

我试图在 View 上显示服务中正在运行的进程的进度。我的 Controller 调用了向第三方发送信息的第一个服务,每次发生这种情况时,我都会通过调用第二个服务进行记录,该服务进行计算以显示请求完成的百分比。

我具有要在第一个服务中更新的值,但不确定如何使用此值更新 View 。在工作完成之前,我不会返回 Controller 。

第一服务

    def batch(toCalculate,otherStuffDoneTotal otherData) {

        def processPercentage

        toCalculate.eachWithIndex(){ data, i ->

            def otherMethod = otherMethod1(doStuffHere)
            def progress = secondService.progressCalc(otherStuffDone, otherStuffDoneTotal, processPercentage)
            }
     }

第二服务
    def progressCalc(otherStuffDoneTotal, otherStuffDone, processPercentage) {

        def retItems
        def retObjs = [:]

        processPercentage = 100 / otherStuffDoneTotal * otherStuffDone

        retItems = [processPercentage: processPercentage]
        retObjs.putAll(retItems)
        return(retOjbs)

    }

如何获取 View 以从第一个服务动态更新值(progress.progressPercentage)

最佳答案

任务并不那么琐碎。

您在这里有3个选择:

  • 简短轮询:创建一个 Controller 操作以返回当前百分比,并使用AJAX函数调用该操作并在 View 中显示进度。
  • 长时间轮询/异步更新。有许多框架对此提供支持,在Java世界中,我建议使用vertx.io,它为您提供了在服务器状态更改时更新 View 的功能
  • 假的。让您的javascript假装从服务器轮询数据,并以一定速度更新百分比。这个解决方案远非完美,但从用户体验
  • 的 Angular 来看可能已经足够了

    关于grails - Grails GSP显示正在计算处理时间的服务变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29011582/

    相关文章:

    Grails Spring Security 插件和 GSP 标签不起作用

    grails - 更改Grails的默认index.gsp页?

    grails - Grails 1.1.1 或 Grails 1.2 M4 中带有连字符的 URL

    java - 如何与Service层操作JDBC连接

    java - 是否可以在 JBoss 定时服务中使用 Seam?

    java - 关于编写 JNDI 服务提供程序的教程

    html - Grails gsp 文件的所见即所得 HTML 编辑器

    grails - WebLogic安装错误-无法访问所选的应用程序

    java - Grails:如何处理 JSR 303 bean 验证

    grails - GORM中的标准制定