我在控制器内部的非常简单的更新操作中使用grails validate()函数。问题非常严重。 validate
()根本没有执行,没有错误并且停止执行。我使用的是Grails 2.3.3
只有日志会出现以下错误:
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"
}
}
Stacktrace:
Request received for '/study/update':
org.apache.catalina.connector.RequestFacade@1eaba95c
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.springframework.security.authentication.UsernamePasswordAuthenticationToken@f6816ea3: Principal: grails.plugin.springsecurity.userdetails.GrailsUser@b29dace9: Username: creator@example.com; Password: [PROTECTED]; Enabled: true; AccountNonExpired: true; credentialsNonExpired: true; AccountNonLocked: true; Granted Authorities: ROLE_USER; Credentials: [PROTECTED]; Authenticated: true; Details: org.springframework.security.web.authentication.WebAuthenticationDetails@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.codehaus.groovy.grails.web.servlet.mvc.SimpleGrailsController@98f1784]: 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;
}
}
答案 0 :(得分:1)
从我读过的评论中,您说您没有向域类添加任何约束。据我所知validate()
使用这些约束来检查您的实例是否有错误。例如:
class CartType {
String name
static constraints = {
name blank: false, nullable:false, maxSize: 50
}
String toString(){name}
}
在这个示例类中,我们有一个cartType。当我们调用validate()
grails将检查约束块。在这种情况下,它将检查表单中的名称是否为空,它不能为空,并且它的最大大小为50个字符。
注意:约束块也可以帮助grails构建数据库。
如果您没有声明任何约束,validate()
将无法检查任何内容。当值为null时,您很可能会收到错误,因为默认情况下,nullable设置为false。