简体   繁体   English

Tapestry-用户打开新选项卡时,永久数据将被覆盖

[英]Tapestry - Persistent data is overridden when user opens a new tab

I am using annotation @Persist(PersistenceConstants.SESSION) to make some data persistent. 我正在使用注释@Persist(PersistenceConstants.SESSION)使某些数据持久化。

Problem is that, when user opens a new tab of the same page type, the persistent data is overridden. 问题是,当用户打开相同页面类型的新选项卡时,永久数据将被覆盖。

I want the data to be persistent per page and not per session so that each page has its own set of persistent data. 我希望数据在每个页面而不是每个会话都是持久的,以便每个页面都有自己的持久数据集。 How can I achieve this in Tapestry? 如何在Tapestry中实现呢?

The first question I always ask when someone wants to use the session is "do you really need to use the session?" 我总是在有人要使用会话时问的第一个问题是“您真的需要使用会话吗?”

Without seeing your code it's difficult to help you but I always solve these problems without using the session. 没有看到您的代码很难帮助您,但是我总是在不使用会话的情况下解决这些问题。 If you always pass the identifiers in the URL then you can have the same page open in multiple browser windows for different entities and everything will just work. 如果您始终在URL中传递标识符,则可以在多个浏览器窗口中为不同的实体打开相同的页面,并且一切正常。

Option 1: Use Page activation context (for page loads) and the event context (for eventlink / actionlink) to maintain the entity id's between requests. 选项1:使用页面激活上下文(用于页面加载)和事件上下文(用于事件链接/动作链接)来维护请求之间的实体ID。

Option 2: Use @Persist(PersistenceConstants.CLIENT) which will use request parameters to pass the entity id's between client and server each time. 选项2:使用@Persist(PersistenceConstants.CLIENT),它将使用请求参数每次在客户端和服务器之间传递实体ID。

If you really want to use the HTTPSession, you can use tapestry-conversations but please consider this a last resort after considering the two stateless / URL based approaches I've mentioned above. 如果您确实想使用HTTPSession,则可以使用Tapestry-conversation,但是在考虑了我上面提到的两种基于无状态/ URL的方法之后,请将此作为最后的选择。

Define a page property as: @Persist(PersistenceConstants.SESSION) means it is stored in the user session in the web container and shared by all requests for the same user. 将页面属性定义为:@Persist(PersistenceConstants.SESSION)表示它存储在Web容器中的用户会话中,并由同一用户的所有请求共享。 Opening a new tab in the browser will identify it as the same client to the server thus reuse the same user session. 在浏览器中打开新选项卡会将其标识为服务器的相同客户端,从而重复使用相同的用户会话。

I want the data to be persistent per page and not per session so that each page has its own set of persistent data. 我希望数据在每个页面而不是每个会话都是持久的,以便每个页面都有自己的持久数据集。

This is probably not something that can be supported by Tapestry out-of-box unless you implement you own persist strategy, which takes a client page id that is unique among multiple tabs of the same pages. 除非您实施自己的持久策略,否则Tapestry可能无法通过开箱即用的方式来支持该策略,该策略采用的客户端页面ID在同一页面的多个选项卡中是唯一的。 But this sounds like bad idea and I will probably never try to do something like that. 但这听起来是个坏主意,我可能永远也不会尝试做类似的事情。

Refer to the suggested answer above. 请参考上面的建议答案。 If you don't find what you want and you're building something that is client-heavy, I think you might need to resort to use the browser local storage in JavaScript to achieve what you want. 如果找不到您想要的东西,并且正在构建大量客户端的东西,我认为您可能需要诉诸使用JavaScript中的浏览器本地存储来实现想要的东西。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Tapestry 5:持久性页面数据的初始化 - Tapestry 5: initialization of persistent page data 在新的浏览器选项卡上的最终用户会话 - End user session when on new browser tab Selenium - 单击链接会打开一个新选项卡 - Selenium - Clicking a link opens up a new tab Selenium在SendKeys之后打开新选项卡 - Selenium opens new tab after SendKeys 为什么表单提交会打开新窗口/标签? - Why form submit opens new window/tab? 链接(带有重定向)将以隐身方式打开,或在新标签页中打开,或者显式声明新页面。 只是单击不起作用 - Link (with redirects) opens in incognito or when open in new tab, or new page is explicitly declared. Doesn't work when just clicked WebElement.click()打开新选项卡,而不是在同一选项卡中工作 - WebElement.click() opens new tab instead of working in same tab Chrome 自定义标签在 chrome 中作为新标签打开而不是在应用程序内,为什么? - Chrome custom tab opens as a new tab in chrome not inside the app why? Tapestry 5用户身份验证 - Tapestry 5 user authentication 如何单击iFrame中的链接以打开新标签页并切换到该标签页 - How to click a link within an iFrame which opens a new tab and switch to it
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM