在 grails 中保存页面视图状态
我有一个页面,是由一堆正在渲染的 grails 模板生成的,带有 javascript 小部件和其他内容,为我们正在开发的搜索引擎指定参数。问题是,如果有人点击搜索结果中返回的某个人,并将他们带到另一个页面,然后他们点击浏览器后退按钮,则搜索参数和动态创建的小部件以及以前的搜索结果都会消失。
我真的不想根据搜索参数(我可以将其保存为会话变量)以编程方式重新构建页面,然后我必须再次重新运行搜索查询才能返回结果。有没有办法保存页面创建时的样子?
谢谢
I have a page that is generated from a bunch of grails templates being rendered, with javascript widgets and stuff, that specify parameters for a search engine we are developing. The problem is, if someone clicks on a person returned in the search results and it takes them to another page, and then they hit the browser back button, the search parameters and dynamically created widgets and previous search results are all gone.
I dont really want to have to programmatically re-build the page based on the search parameters (which I can save as a session variable), and I would then have to re-run the search query again to get the results back. is there a way to save a page just as it was created?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
弹出一个 JavaScript 窗口,其中包含有关该人的信息,而不是将他们带到另一个页面。在最坏的情况下,将人员链接的目标设置为 _new ,这将强制打开一个新的浏览器窗口/选项卡。
Popup a javascript window with information about that person instead of taking them to another page. In the worst case set the target of the person link to _new and that will force open a new browser window/tab.
在某些地方必须保存搜索参数。无论是在服务器端还是客户端。在服务器端,您只有
session
或flash
范围选项。在客户端,您可以将这些值存储在 cookie 中。这需要一些 JavaScript 代码。
然而,理论上,浏览器将保持手动更改的表单字段值开箱即用。他通过名称/ID 来识别表单字段。不需要以编程方式执行任何操作,除非您通过 AJAX 加载页面的某些部分。也许您可以仔细检查输入字段是否具有静态名称/ID 对,或者您有一些元/缓存/html 设置,这些设置禁止这种机制(仔细检查,您的表单没有
autocomplete="off"
它本身不提供开箱即用的功能(我不知道其他框架是否有 - 也许除了 Seam,它有。会话范围的概念;但即使这个功能也不起作用如果用户使用浏览器后退按钮,则开箱即用)最简单的方法是使您的搜索页面可缓存(对于浏览器,通过设置 HTTP 标头或元标记),以便浏览器可以缓存。如果用户按下浏览器后退按钮,则不会尝试再次从服务器重新加载页面,并仔细检查
autocomplete="off"
设置。At some place the search parameters have to be saved. Either on server or client side. On the server side you only have the options
session
orflash
scope.On the client side you could store those values in a cookie. This needs some bits of javascript.
However theoretically the browser will keep manually changed form field-values out of the box. He is identifying the form fields by its name/id. It should not be necessary to do any programmatically things, except if you are loading some parts of the page via AJAX. Maybe you can doublecheck, that the input fields have static name/id pairs or you have some meta/cache/html settings, which prohibit such mechanism (double check, that your form does not have
autocomplete="off"
setting set. This will prevent the browser to refill your form fields.Grails itself does not offer things like you need out-of-the-box (and I do not know if other frameworks have - maybe except for Seam, which has a concept of conversation scope; but even this feature will not work out-of-the-box if the user uses the browser back button). The easiest way is to make your search page some kind of cacheable (for the browser, by settings HTTP-headers or meta tags), so that the browser is not trying to reload the page from the server again, if the user presses the browser back button. And double check the
autocomplete="off"
setting.