1

Could anyone explain me what is the Wicket's page versioning useful for? There is an article in the FAQ that is related to this topic:

Wicket stores versions of pages to support the browser's back button.

Suppose you have a paging ListView with links in the ListItems, and you've clicked through to display the third page of items. On the third page, you click the link to view the details page for that item. Now, the currently available state on the server is that you were on page 3 when you clicked the link. Then you click the browser's back button twice (i.e. back to list page 3, then back to list page 2, but all in the browser). While you're on page 2, the server state is that you're on page 3. Without versioning, clicking on a ListItem link on page 2 would actually take you to the details page for an item on page 3.

But unfortunately I don't understand it at all. When I click on a ListItem on page 2, I would expect to get to the page defined by that Link - details page for the item. Why should I get on the details page of the item on page 3?

Moreover, when one press the back button in a browser, it doesn't call the server at all. Is it right?

So how this versioning works?

4

1 回答 1

3

不,当您按下后退按钮时,服务器不会收到通知。我将尝试解释示例中发生的情况:

  • 您第一次访问您的应用程序。在服务器上,创建了一个页面“列表”,用于呈现您在浏览器中看到的 HTML,并存储为页面 v1。您会看到列表的前 10 项。

  • 您单击“下一个”链接,它指的是页面 v1 中的链接。在服务器上,加载页面 v1,执行链接逻辑(推进分页),页面用于呈现 HTML,并存储为页面 v2。您会看到从 11 到 20 的项目。

  • 您单击“下一个”链接,它指的是第 v2 页中的链接。在服务器上,加载页面 v2,执行链接逻辑(推进分页),页面用于呈现 HTML,并存储为页面 v3。您会看到从 21 到 30 的项目。

  • 您单击第 25 项的“详细信息”链接,它指的是页面 v3 中第 5 项的链接(此页面仅显示 10 项,并且链接,即使它指的是完整列表中的第 25 项,在这一页只是第 5 页)。在服务器上,加载页面 v3,执行其逻辑,创建页面“详细信息”,存储为页面 v4,然后将您重定向到它。您的浏览器请求页面 v4,服务器加载它,并使用它来呈现您的 HTML 页面(没有存储新版本,因为它只是呈现)。您会看到第 25 项的详细信息。

  • 您单击浏览器的“返回”按钮 2 次,看到显示第 11 至 20 项的页面“列表”,参考页面 v2(列表)。然后单击第 13 项的链接“详细信息”。在服务器上,页面v2已加载(不是 v4,最后执行的页面),因为单击的链接指向此页面版本。然后,执行第 3 个项目链接的逻辑,创建一个新页面“详细信息”,存储为页面v5,并将您重定向到它。浏览器请求页面 v5,服务器加载它,并使用它来呈现您的 HTML。您会看到第 3 项的详细信息。

如果您来自类似 Struts 的背景,所有这一切可能看起来很奇怪,您总是只是将项目 id 或要显示的页面作为链接参数。在 Wicket 中,通常的情况是将所有状态存储在服务器中,并且导航不是由客户端完成(直接链接到传递参数的另一个页面),而是在服务器中。链接只是要求服务器在页面对象版本中执行代码,导航是在服务器端完成的。

您可能会争辩说 Struts 风格更简单(您也可以在 Wicket 中做到这一点,只是不是最佳的),但仅将状态保留在服务器中具有许多优点。拳头,一旦习惯了,其实就容易多了。无需将每个参数添加到分页链接(搜索参数、第一项、页面长度、排序列、排序方向等)。此外,您避免了许多安全问题(您不能只是将 URL id 参数更改为任意值并访问其他用户的数据),并且可以通过 Java 代码而不是混合 Java-Javascript 来控制所有内容(如果不过,你想要)。

于 2013-06-12T17:58:30.263 回答