Validation Grails验证运行时错误
我在控制器内非常简单的更新操作中使用grailsvalidate()函数。问题很严重<代码>验证(validate)()完全不执行,不给出任何错误并停止执行。我正在使用Grails2.3.3 只有日志显示以下错误:Validation Grails验证运行时错误,validation,grails,runtime-error,Validation,Grails,Runtime Error,我在控制器内非常简单的更新操作中使用grailsvalidate()函数。问题很严重验证(validate)()完全不执行,不给出任何错误并停止执行。我正在使用Grails2.3.3 只有日志显示以下错误: Runtime error executing action 这是我的控制器代码: def update() { println(params); def study = Study.findByUid(params.uid); st
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':
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)
......
/
从我读到的评论中,您说您没有向域类添加任何约束。据我所知,
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。请发布完整的StackTrace,并发布您的约束您可以发布研究
类吗?谢谢。我需要任何包含或任何东西吗?请发布您的域类和URL映射的代码。你改变了地图吗?
class CartType {
String name
static constraints = {
name blank: false, nullable:false, maxSize: 50
}
String toString(){name}
}