正在调用Grails Redirect但未呈现页面

时间:2012-11-01 21:43:24

标签: grails redirect twitter-bootstrap controller modal-dialog

下午好朋友。

在过去的几天里,我一直在努力解决一个非常令人沮丧的问题,最后我终于走到了尽头。我团队中的每个人都有一点时间似乎无法弄清楚这个问题,这让我疯了!

无论如何,我有一个带有删除操作的Controller,当用户确认从Bootstrap模式对话框中删除时会调用该操作。调用该操作,并且调试中的重定向语句就好了。它甚至将Chrome开发人员工具中的调用显示为被调用!

但是,出于某种原因,页面永远不会重定向。我甚至尝试过明确地重定向到Google,而没有其他代码。我不知道这笔交易是什么。我会发布任何相关的代码;如果您需要其他代码,请告诉我。

CatalogController.groovy

def delete = {
    def catalog = Catalog.get(params.id)
    if (catalog == null) {
        redirect(controller: 'home', action: 'dashboard')
        println "Catalog is null and cannot be Deleted"
        return
    }

    if (request.method == "POST") {
        //catalog.deleted = true TESTING UNTIL REDIRECT WORKS 
        if (catalog.validate()) {
            userService.addUserActivity("Deleted catalog " + catalog.title, catalog.class.getName(), catalog.id, null)
            flash.notice = "Catalog has been deleted"
            catalog.save()
            println "Catalog successfully deleted"
        }
        else {
            flash.error = "There was an error marking the catalog deleted"
        }

        redirect(controller: 'home', action: 'dashboard')
        return
    }

    [ catalog: catalog ]
}

引导模式标记

<div id="deleteDialog" class="modal hide fade" tabindex="-1" role="dialog"  aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal"
            aria-hidden="true">×</button>
        <h3 id="myModalLabel">Delete Catalog</h3>
    </div>
    <div class="modal-body">
        <p><strong>Are you sure you want to delete this Catalog?</strong></p>

        <div class="dialogInnerInfo">
            <div class="row-fluid control-group">
                <label class="control-label" for="catalogNumber">Catalog Number:</label>
                <div class="controls">
                    <label id="catalogNumber" >${catalog.legacyId}</label>
                    <input type="hidden" name="id" value="${catalog.id}"/>
                </div>
            </div>

            <div class="row-fluid control-group">
                <label class="control-label" for="catalogTitle">Catalog Title:</label>
                <div class="controls">
                    <label id="catalogTitle">${catalog.title}</label>
                </div>
            </div>

            <div class="row-fluid control-group">
                <label class="control-label" for="catalogTitle">Number of Samples:</label>
                <div class="controls">
                    <label id="catalogTitle">${catalog.sampleCount}</label>
                </div>
            </div>
        </div>
    </div>
    <div class="modal-footer">
            <g:remoteLink class="btn btn-primary" controller="catalog" action="delete" id="${catalog.id}" data-dismiss="modal">Yes</g:remoteLink>
            <button class="btn btn-primary" value="${catalog.id}" data-dismiss="modal" onclick="${remoteFunction(action:'delete', controller: 'catalog', params: '\'id=\'  + this.value')}">Click Here</button>
            <button class="btn" data-dismiss="modal" aria-hidden="true">No</button>
        </div>
    </div>

我尝试了各种不同的按钮(g:链接,按钮,g:remoteLinks等)并清理了删除操作。我还尝试删除我的浏览器缓存,grails缓存,运行grails-clean和一系列其他任务,以查看问题是否在我的环境中,但其他人也没有获得重定向。

请原谅丑陋的编码,一旦重定向工作,它就会被清理干净。我也欢迎建议和改进:)

非常感谢您的时间和帮助!

1 个答案:

答案 0 :(得分:0)

当前显示的版本无法工作,因为remotelink不会执行重定向,因为响应是从JS解析的。您需要在JavaScript中手动处理它,或者使用g:link。

此外,您不能将data-dismiss="modal"与链接结合使用,因为Twitter引导程序将拦截您的点击并阻止任何进一步的服务器通信。如果删除data-dismiss =“modal”,它将起作用。

相关问题