Grails控制器未将错误传递到gsp页面

Grails控制器未将错误传递到gsp页面,grails,groovy,Grails,Groovy,我不知道我做错了什么。我希望这是一件微妙的事情。我似乎无法将错误传递到我的gsp页面。我的控制器中有以下代码: def submit = { if (params) { // if there are parameters def sampleInstance = new Sample(params)// new sample if (sample.validate()) { // try to validate sample.sa

我不知道我做错了什么。我希望这是一件微妙的事情。我似乎无法将错误传递到我的gsp页面。我的控制器中有以下代码:

def submit = {
    if (params) { // if there are parameters
        def sampleInstance = new Sample(params)// new sample
        if (sample.validate()) { // try to validate
            sample.save()
            flash.message = "Successfully Entered Sample"
            redirect ( action: 'sample' )
        }else{
            flash.message = "Error Entering Sample"
            sampleInstance.errors.each {
                println it
            }
            redirect ( action: 'sample', model:[sampleInstance:sampleInstance])
        }
    } 
}
我已经验证了params不是null。验证失败将创建hasErrors(),该错误也已验证,并且代码
sample.errors.each{println it}
会通知我预期的正确字段错误。但我的重定向语法可能有问题?因为
flash.message
将起作用,但我无法访问
模型:[sampleInstance:sampleInstance]
映射,并且不会呈现任何错误

以下是我的gsp中的代码:

     <g:hasErrors>
        <div class="errors">
         <g:renderErrors bean="${sampleInstance}" as="list" />
        </div>

     </g:hasErrors>

在重定向中,该模型用作查询参数,与render不同,render执行实际的forward并将对象放入请求范围。如果出现错误,需要执行的操作是渲染视图并传递模型。然后您将获得所需的输出。

在重定向中,该模型用作查询参数,与render不同,render执行实际的forward并将对象放入请求范围。如果出现错误,需要执行的操作是渲染视图并传递模型。然后您将获得所需的输出。

谢谢您的帮助。为了简化事情,我最终将我的两个动作合并为一个动作,但很高兴知道我可以在同一个gsp页面上使用多个动作。干杯谢谢,这很有效。为了简化事情,我最终将我的两个动作合并为一个动作,但很高兴知道我可以在同一个gsp页面上使用多个动作。干杯
def sample(){
    def now = new Date()// today's date
    def today = com.Sample.findAllBySampleReceivedDateGreaterThanEquals(now.clearTime())// finds all samples submitted today
   [checkDate:today, date: now] // passes a map of checkDate and todays date to the sample.gsp page
}