gpt4 book ai didi

grails - Grails Web-flow 中的重定向

转载 作者:行者123 更新时间:2023-12-01 15:04:36 25 4
gpt4 key购买 nike

我对 Grails 网络流程中的重定向有疑问。我处于允许用户输入问题答案的 View 状态。在 2 次错误尝试中,我应该能够重定向用户以从不同的 Controller 查看页面。我的意思是

challengeQuestionOne{
onRender() {
//Display question
}
on('next') {BuildQuestion command ->
bindData(flow.recovery,command)
[return the model to flow]
if(command.hasErrors()) {
flow.command = command
return error()
}
if(check for status. If doesnot pass){
flash.message=message(code:'loginForm.account.locked', default: 'Please Contact Admin.')
redirect(controller : "login",action: "login")//how to redirect from here to diff controller
}
if (//compare answer entered) {

}
else{
//set status not active
}

}.to("challengeQuestionTwo")
on(Exception).to("error")
on('cancel').to('finish')
}

我试图从 onRender 重定向。它正在重定向到页面。但是如何在重定向页面上显示错误消息。我如何将错误消息从一个 Controller 转发到另一个 Controller ?

最佳答案

Ivo Houbrechts 写了一篇关于 grails webflow 的优秀教程:

Webflow defines its own flash scope. Although it has the same semantics as the standard grails flash scope (the main purpose is to store objects only until after the next request), it is a different scope. This means that objects stored in webflow's flash scope are not visible in standard grails actions.

import org.springframework.web.context.request.RequestContextHolder
....
RequestContextHolder.currentRequestAttributes().flashScope.message = "YourMessage"

您可以在这里阅读更多内容:

http://livesnippets.cloudfoundry.com/docs/guide/

关于grails - Grails Web-flow 中的重定向,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10543757/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com