在渲染与操作同名的视图时,Grails会重定向循环错误 [英] Grails redirect looping error when rendering view with the same name as action

查看:145
本文介绍了在渲染与操作同名的视图时,Grails会重定向循环错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Grails 2.2.3来清除数据库中的重复人员。当我尝试访问控制器操作时,我收到以下错误消息:



错误由org.codehaus.groovy.grails.web引起.servlet.mvc.exceptions.CannotRedirectException:无法在此处发出重定向(..)。先前调用重定向(..)已经重定向了响应。



它看起来像一个无限重定向循环,因为Stacktrace在一旦我进入 duplicate()操作,控制台就会变得疯狂。它一直保持打印状态,直到我从控制台中取出 Ctrl + C 。此外,还有多个屏幕用于处理重复并修复它,这就是为什么我要存储工作重复的方式。



控制器操作:




  • setWorkingDuplicate - 设置重复以使用(因此用户不必继续输入)。

  • 重复 - 查看重复或,如果没有 session.id,用户找到重复表单

  • <$











    $ p>直接进入duplicate()页面时发生错误。如果我先设置工作副本,则不会发生重定向问题。



    以下是导致此问题的控制器操作。

      def setWorkingDuplicate(Integer id){
    if(id& amp; Duplicate.get(id)){
    session.id = id
    flash.message =工作重复设置为ID $ {id}
    重定向操作:'getDuplicate',params:[id:session.id]
    }
    }

    def duplicate(){
    if(session.id){
    redirect(action:'getDuplicate',params:[id:session.id])
    return

    render view:'duplicate'
    }

    def getDuplicate(Integer id){
    def duplicate = Duplicate.get(id)

    if(!duplicate){
    flash.message =重复找不到ID $ {id}。
    render(view:'duplicate')
    return
    }

    render view:'duplicate',model:[duplicate:duplicate]
    }

    有人知道这可能是什么原因吗?

    <编辑:它看起来像在堆栈跟踪中的某处,我也收到以下错误。

     错误导致:java .lang.StackOverflowError 

      WARN:Exception:java.lang.reflect.InvocationTargetException 

    堆栈跟踪,以下错误不断重复:

      | edu.mssu.duplicates.InitialStepsController.render错误(InitialStepsController.groovy)
    | edu.mssu.duplicates.InitialStepsController中的错误$ render.callCurrent(Unknown Source)
    | edu.mssu.duplicates.InitialStepsController.getDuplicate错误(InitialStepsController.groovy:69)
    | edu.mssu.duplicates.InitialStepsController.getDuplicate错误(InitialStepsController.groovy)
    |错误在sun.reflect.GeneratedMethodAccessor382.invoke(未知源)
    |错误在sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    | java.lang.reflect.Method.invoke(Method.java:601)
    |错误org.springsource.loaded.ri.ReflectiveInterceptor.jlrMethodInvoke(ReflectiveInterceptor.java:1259)
    | org.apache.commons.beanutils.BeanMap.get(BeanMap.java:390)
    | org.apache.commons.beanutils.BeanMap $ 12.next(BeanMap.java:565)
    | org.apache.commons.collections.iterators.UnmodifiableIterator.next(UnmodifiableIterator.java:72)
    | java.util.HashMap.putAll(HashMap.java:621)
    |时出错org.springframework.ui.ModelMap.addAllAttributes错误(ModelMap.java:117)
    | org.springframework.web.servlet.ModelAndView。< init>(ModelAndView.java:97)
    | org.codehaus.groovy.grails.web.metaclass.RenderDynamicMethod.renderView(RenderDynamicMethod.java:485)出现错误
    | org.codehaus.groovy.grails.web.metaclass.RenderDynamicMethod.invoke(RenderDynamicMethod.java:187)中的错误
    | org.codehaus.groovy.grails.plugins.web.api.ControllersApi.invokeRender(ControllersApi.java:258)
    | org.codehaus.groovy.grails.plugins.web.api.ControllersApi.render(ControllersApi.java:246)


    $ b错误$ b

    这是我的重复GSP(非常精简版)的版本。 GSP提供了一种快速搜索/显示/更新复制并在一页中显示该复制的方法。因此,搜索框和显示表单。

     <%@ page contentType =text / html; charset = UTF-8 %GT; 
    < html>
    < head>
    < / head>
    < body>
    < h1>重复< / h1>
    < label for =id>重复ID< / label> < g:textField name =idvalue =$ {duplicate?.id}/>

    < / g:表格>

    //表单内容

    < g:hiddenField name =idvalue =$ {duplicate?.id}/>
    < / g:表格>
    < / g:if>
    < / body>
    < / html>


    解决方案

    在命名之前,我遇到了一些非常奇怪的问题控制器匹配一些其他对象或以'get'开始



    尝试重命名:

    def getDuplicate(Integer id) code>
    到完全不同的东西,例如: def myDupe(Integer id)



    对不起我不能给你一个更好的解释,但我已经做了几次,只是为了让事情有效。


    I am using Grails 2.2.3 for an app to clear out Duplicate persons in our Database. When I attempt to access a controller action, I am receiving the following error:

    Error Caused by: org.codehaus.groovy.grails.web.servlet.mvc.exceptions.CannotRedirectException: Cannot issue a redirect(..) here. A previous call to redirect(..) has already redirected the response.

    It looks like an infinite redirect loop, because the Stacktrace in the console just goes bonkers as soon as I go to the duplicate() action. It keeps printing until I Ctrl+C out of the console. Also, there are multiple screens for working with a Duplicate and fixing it, which is why I am giving a way to store the "working" Duplicate.

    The controller actions:

    • setWorkingDuplicate - set a duplicate to work with on each page (so a user doesn't have to keep typing it in).
    • duplicate - view a duplicate or, if there is no session.id, present the user with find duplicate form
    • getDuplicate (action only) - gets a duplicate and renders the duplicate page

    The error is occurring when I go straight to the duplicate() page. If I set the working duplicate first, no redirect issues happen.

    Here are the controller actions that are causing the issue.

    def setWorkingDuplicate(Integer id) {
        if (id && Duplicate.get(id)) {
            session.id = id
            flash.message = "Working Duplicate set to ID ${id}"
            redirect action: 'getDuplicate', params: [id: session.id]
        }
    }
    
    def duplicate() {
        if (session.id) {
            redirect(action: 'getDuplicate', params: [id: session.id])
            return
        }
        render view: 'duplicate'
    }
    
    def getDuplicate(Integer id) {
        def duplicate = Duplicate.get(id)
    
        if (!duplicate) {
            flash.message = "Duplicate not found with ID ${id}."
            render(view: 'duplicate')
            return
        }
    
        render view: 'duplicate', model: [duplicate: duplicate]
    }
    

    Does anyone know what might be causing this?

    Edit: it looks like somewhere down in the stack trace I am also receiving the following errors.

    Error Caused by: java.lang.StackOverflowError
    

    and

    WARN: Exception: java.lang.reflect.InvocationTargetException
    

    And in the stack trace, the following errors keep repeating over and over:

    | Error     at edu.mssu.duplicates.InitialStepsController.render(InitialStepsController.groovy)
    | Error     at edu.mssu.duplicates.InitialStepsController$render.callCurrent(Unknown Source)
    | Error     at edu.mssu.duplicates.InitialStepsController.getDuplicate(InitialStepsController.groovy:69)
    | Error     at edu.mssu.duplicates.InitialStepsController.getDuplicate(InitialStepsController.groovy)
    | Error     at sun.reflect.GeneratedMethodAccessor382.invoke(Unknown Source)
    | Error     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    | Error     at java.lang.reflect.Method.invoke(Method.java:601)
    | Error     at org.springsource.loaded.ri.ReflectiveInterceptor.jlrMethodInvoke(ReflectiveInterceptor.java:1259)
    | Error     at org.apache.commons.beanutils.BeanMap.get(BeanMap.java:390)
    | Error     at org.apache.commons.beanutils.BeanMap$12.next(BeanMap.java:565)
    | Error     at org.apache.commons.collections.iterators.UnmodifiableIterator.next(UnmodifiableIterator.java:72)
    | Error     at java.util.HashMap.putAll(HashMap.java:621)
    | Error     at org.springframework.ui.ModelMap.addAllAttributes(ModelMap.java:117)
    | Error     at org.springframework.web.servlet.ModelAndView.<init>(ModelAndView.java:97)
    | Error     at org.codehaus.groovy.grails.web.metaclass.RenderDynamicMethod.renderView(RenderDynamicMethod.java:485)
    | Error     at org.codehaus.groovy.grails.web.metaclass.RenderDynamicMethod.invoke(RenderDynamicMethod.java:187)
    | Error     at org.codehaus.groovy.grails.plugins.web.api.ControllersApi.invokeRender(ControllersApi.java:258)
    | Error     at org.codehaus.groovy.grails.plugins.web.api.ControllersApi.render(ControllersApi.java:246)
    

    This is a (very stripped down) version of my Duplicate GSP. The GSP presents a way to quickly search/show/update a Duplicate and display that Duplicate, all in one page. Hence the search box and show form.

    <%@ page contentType="text/html;charset=UTF-8" %>
    <html>
    <head>
    </head>
    <body>
        <h1>Duplicate</h1>
            <g:form action="duplicate" method="POST">
                <label for="id">Duplicate ID</label> <g:textField name="id" value="${duplicate?.id}" />
    
                <g:submitButton name="btnRetrieveDuplicate" value="Retrieve Duplicate" />
            </g:form>
    
            <g:if test="${duplicate}">
                <g:form action="updateDuplicate" method="POST">
                    //Form stuff
    
                    <g:hiddenField name="id" value="${duplicate?.id}" />
                </g:form>
            </g:if>
    </body>
    </html>
    

    解决方案

    I've had some really strange issues before when naming controllers matched some other objects or started with 'get'

    Try renaming:
    def getDuplicate(Integer id) to something completely different like: def myDupe(Integer id)

    Sorry I can't give you a better explanation, but I've done this a few times just to get things working.

    这篇关于在渲染与操作同名的视图时,Grails会重定向循环错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆