2013-11-27 47 views
0

我在控制器內的非常簡單的更新操作中使用grails validate()函數。問題非常嚴重。 validate()根本不執行,並且不會發生錯誤並停止執行。我使用的Grails 2.3.3Grails驗證運行時錯誤

只有日誌提供了以下錯誤:

Runtime error executing action 

這裏是我的控制器代碼:

def update() { 

     println(params); 

     def study = Study.findByUid(params.uid); 
     study.description = params.description; 

     println(study); //study is found and printed 
     study.validate(); 
     println("here"); //not executed and code below is also not executed 

     if(study.hasErrors()){ 
      study.errors.each{ 
       println it 
      } 
      render 'not saved!' 
     } 

     if (!study.save()) { 

      println("Error"); 
      withFormat renderInternalError 
     } 
     else { 

      render "OK" 
     } 
    } 

堆棧跟蹤:

Request received for '/study/update': 

[email protected] 

servletPath:/study/update 
pathInfo:null 

Security filter chain: [ 
    SecurityContextPersistenceFilter 
    MutableLogoutFilter 
    RequestHolderAuthenticationFilter 
    SecurityContextHolderAwareRequestFilter 
    GrailsRememberMeAuthenticationFilter 
    GrailsAnonymousAuthenticationFilter 
    ExceptionTranslationFilter 
    FilterSecurityInterceptor 
] 


************************************************************ 


2013-11-27 11:56:04,738 [http-bio-8080-exec-9] DEBUG filter.GrailsRememberMeAuthenticationFilter - SecurityContextHolder not populated with remember-me token, as it already contained: 'org.springframew[email protected]f6816ea3: Principal: [email protected]: Username: [email protected]; Password: [PROTECTED]; Enabled: true; AccountNonExpired: true; credentialsNonExpired: true; AccountNonLocked: true; Granted Authorities: ROLE_USER; Credentials: [PROTECTED]; Authenticated: true; Details: org.sprin[email protected]1c07a: RemoteIpAddress: 127.0.0.1; SessionId: A1813ED8541AAC773CEF349475DB24A2; Granted Authorities: ROLE_USER' 
2013-11-27 11:56:04,738 [http-bio-8080-exec-9] DEBUG filter.GrailsAnonymousAuthenticationFilter - SecurityContextHolder not populated with anonymous token, as it already contained: '{0}' 
2013-11-27 11:56:04,740 [http-bio-8080-exec-9] TRACE intercept.AnnotationFilterInvocationDefinition - new candidate for '{0}': '{1}':{2} 
2013-11-27 11:56:04,740 [http-bio-8080-exec-9] TRACE intercept.AnnotationFilterInvocationDefinition - config for '{0}' is '{1}':{2} 
2013-11-27 11:56:04,741 [http-bio-8080-exec-9] TRACE core.StandardWrapper - Returning non-STM instance 
2013-11-27 11:56:04,743 [http-bio-8080-exec-9] DEBUG simple.MemoryPageFragmentCachingFilter - No cacheable annotation found for POST:/hdspro/grails/study/update.dispatch [controller=study, action=update] 
2013-11-27 11:56:05,651 [http-bio-8080-exec-9] DEBUG errors.GrailsExceptionResolver - Resolving exception from handler [org.codeh[email protected]]: org.codehaus.groovy.grails.web.servlet.mvc.exceptions.ControllerExecutionException: Executing action [update] of controller [com.digithurst.hdspro.StudyController] caused exception: Runtime error executing action 
2013-11-27 11:56:05,651 [http-bio-8080-exec-9] DEBUG errors.GrailsExceptionResolver - Resolving to view '/error' for exception of type [org.codehaus.groovy.grails.web.servlet.mvc.exceptions.ControllerExecutionException], based on exception mapping [java.lang.Exception] 
2013-11-27 11:56:05,651 [http-bio-8080-exec-9] DEBUG errors.GrailsExceptionResolver - Exposing Exception as model attribute 'exception' 
2013-11-27 11:56:05,951 [http-bio-8080-exec-9] ERROR errors.GrailsExceptionResolver - StackOverflowError occurred when processing request: [POST] /hdspro/study/update - parameters: 
acessionNumber: 3 
uid: 3 
description: Elbogen123 
Stacktrace follows: 
org.codehaus.groovy.grails.web.servlet.mvc.exceptions.ControllerExecutionException: Executing action [update] of controller [com.digithurst.hdspro.StudyController] caused exception: Runtime error executing action 
    at grails.plugin.cache.web.filter.PageFragmentCachingFilter.doFilter(PageFragmentCachingFilter.java:200) 
    at grails.plugin.cache.web.filter.AbstractFilter.doFilter(AbstractFilter.java:63) 
    at grails.plugin.springsecurity.web.filter.GrailsAnonymousAuthenticationFilter.doFilter(GrailsAnonymousAuthenticationFilter.java:53) 
    at grails.plugin.springsecurity.web.authentication.RequestHolderAuthenticationFilter.doFilter(RequestHolderAuthenticationFilter.java:49) 
    at grails.plugin.springsecurity.web.authentication.logout.MutableLogoutFilter.doFilter(MutableLogoutFilter.java:82) 
    at grails.plugin.springsecurity.web.filter.DebugFilter.invokeWithWrappedRequest(DebugFilter.java:102) 
    at grails.plugin.springsecurity.web.filter.DebugFilter.doFilter(DebugFilter.java:69) 

...... 

/

Study class: 
class Study extends Document { 

    String uid 
    String description 
    String accessionNumber 
    Date date 

    String toString(){ 
     return "Study" + uid + ": " + description; 
    } 
} 
+1

請發佈完整的stacktrace – Alidad

+0

,並請張貼您的約束 –

+0

我沒有他們 – Jacob

回答

1

從我讀過的評論,你說你沒有添加任何約束域類。從我所知道的validate()使用這些約束來檢查你的實例是否有錯誤。例如:

class CartType { 
    String name 
    static constraints = { 
     name blank: false, nullable:false, maxSize: 50 
    } 

    String toString(){name} 
} 

在這個示例類中,我們有一個cartType。當我們調用validate()時,grails會檢查約束塊。在這種情況下,它會檢查表單中的名稱不是空白,它不能爲空,並且它的最大大小爲50個字符。

說明:約束塊也可以幫助grails構建數據庫。

如果您沒有聲明任何限制validate()將不會有任何檢查。當值爲空時,您也很可能會遇到錯誤,因爲默認情況下,nullable設置爲false。