在grails中请求变量 [英] request variables in grails

查看:110
本文介绍了在grails中请求变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

编辑:基于反馈,完全删除原始Q.并以更好的语言重新发布我希望访问请求或params变量并在控制器和gsp之间传递。我明白params对象包含查询字符串的所有内容。



我看到的所有示例都是模型驱动的。
我在网上查阅了文档,并且我有两本书 - Grails初学者指南和Grails的权威指南,都有关于params的数据库驱动示例。我想了解如何设置和访问参数。所有我到处读的是它是一个请求变量的映射。

我的场景如下:
我有一个控制器,它发送一个列表一个数据库)给普惠制。我想在GSP和控制器之间传递一个params变量。

重申,我拥有的场景不是模型驱动的场景。我正在寻找迭代通过项目列表(没有数据库已知数量),并由用户单击驱动。我想到实现类似Twitter的更多按钮这样的东西。在页面底部有一个简单的remotelink和一个新的页面计数器,我可以在控制器中访问,并通过我的服务类来获取列表的新部分。



控制器代码:

  //从请求
访问参数int pageInt = params [pagecount] // * i总是在此处获得空值*

callMyList(pagecount)//调用我的服务方法获取下一页的下一组列表

GSP(不是实际)代码

 <%= params.get( pagecount)%> 
<%= nxtPage = pagecount ++%>
...
<%params [myId] = nxtPage%>



解决方案

params对象仅用于获取值来自当前请求的查询字符串。 在GSP中设置参数值不会做任何事情。 Params是一个请求范围对象,每个新的请求都是一个全新的对象。要将您的GSP中的值传递给您的List控制器,该值必须位于对控制器的新请求的查询字符串中。在你的情况下,它看起来像你想把它放在你的更多链接。你的remoteLink标签被写入的方式,nxtPage的值应该在你的List控制器的params.id中,所以你可以这样访问它。如果你想在params.pagecount中,你必须把它放在你的remoteLink标签的params属性中。就像这样:

 < g:remoteLink action =listparams =[pagecount:nxtPage]>更多< /克:remoteLink> 


EDIT: based on feedback, erased original Q. completely and reposting in better language

I wish to access a request or params variable and pass it between the controller and the gsp. i understand that the params object contains everything that a querystring has.

All the examples I see are all Model driven. I have looked up docs online and I have two books - beginning-grails and definitive guide to grails, both have database driven examples on params. I want to understand how params can be set and accessed. All I read everywhere is that it is a map of request variables.

My scenario is as follows: I have a controller which sends a list (not from a database) to the GSP. I thought of passing a "params" variable between GSP and the controller.

To reiterate, the scenario I have is not a Model driven one. I am looking to iterate thru a list of items (with no database count known) and is driven by user click. I thought of implementing something like what twitter has "the-more-button-on-the-bottom". have a simple remotelink at the bottom of the page with a new page counter, which i access in the controller and pass to my service class for the new part of list.

controller code:

//access params from request
int pageInt =params["pagecount"] // *i always get null here*

callMyList(pagecount) //calls my service method to get next set of list for next page

GSP (not actual) code

 <%= params.get("pagecount") %>
 <%= nxtPage = pagecount++ %>
  ...
 <%params["myId"] = nxtPage%>


<g:remoteLink action="list" id="${nxtPage}">More</g:remoteLink>

解决方案

The params object is only useful for getting values from the query string of the current request. Setting a value in params in a GSP won't do anything. Params is a request scope object, with each new request it is an entirely new object. To pass a value from your GSP to your List controller, that value must be in the query string of the new request to the controller. In your case, it looks like you want to put it in your "More" link. The way your remoteLink tag is written, the value of nxtPage should be in params.id in your List controller, so you could access it that way. If you want to be in params.pagecount you would have to put it in the params attribute of you remoteLink tag. Something like this:

<g:remoteLink action="list" params="[pagecount: nxtPage]">More</g:remoteLink>

这篇关于在grails中请求变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆