从 Grails Webflow 访问请求参数
我正在使用 Grails webflow,并且在读取请求中的参数值时遇到了令人惊讶的困难。我定义了一个简单的流程如下:
def testFlow = {
stepOne{
String name = params.name
render(view: "stepTwo", [name: name])
}
...
}
我遇到的问题是名称参数没有解析为我在请求中传递的名称值,而是为它分配了字符串值“org.codehaus.groovy” .grails.commons.metaclass.PropertyExpression”是 Grails 控制器中存在的隐式“params”对象的类名称。
如果我将相同的参数分配放在非 Webflow 控制器闭包(即标准控制器闭包)中,则该分配将按照您的预期工作,并且“名称”对象将分配我通过请求参数传入的值。
我是否在这里忽略了一些显而易见的事情(这不是第一次)或者其他人是否见过同样的问题?我还尝试使用访问参数值 params['name'] 和 params.getProperty('name') 但在所有情况下结果都是相同的。
I'm playing around with Grails webflow and having surprising difficulty reading param values from the request. I have defined a simple flow as follows:
def testFlow = {
stepOne{
String name = params.name
render(view: "stepTwo", [name: name])
}
...
}
The problem I'm having is that the name parameter is not resolving to the name value I'm passing in in the request, but rather it is assigned the String value "org.codehaus.groovy.grails.commons.metaclass.PropertyExpression" which is the name of the class of the implicit 'params' object that is present in Grails controllers.
If I put the same parameter assignment in a non-webflow controller closure (i.e. a standard controller closure), the assignment works as you would expect and the 'name' object is assigned the value that I pass in via the request params.
Am I overlooking something glaringly obvious here (wouldn't be the first time) or has anyone else seen the same sort of issue? I have also tried accessing the param value using
params['name'] and params.getProperty('name') but in all cases the result is the same.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的流程定义/DSL 看起来并不正确。通常,您不会在 DSL 中使用 render(),因为渲染是根据您的状态名称进行的。此外,
params
通常在action
和/或on
闭包中访问。这是更好、简短的 Grails Web 流程教程之一。 发现 Grails Web 流
Your flow definition/DSL doesn't really look correct. Normally you dont use render() within the DSL, as rendering occurs for you based on your state names. Also,
params
are typically accessed within anaction
and/oron
closure.Here is one of the better, short, grails web flow tutorials. Discovering Grails Web Flows