此内容没有您所选择的语言版本。
1.9. Bookmarkable URLs with the Blog example
Seam makes it easy to implement applications which keep state on the server side. However, server-side state is not always appropriate, particularly for functionality that serves up content. For this, application state is often stored as part of the URL, so that any page can be accessed through a bookmark at any time. The blog example shows how to implement an application that supports bookmarking throughout, even on the search results page. This example demonstrates Seam's management of application state in the URL.
The blog example demonstrates the use of "pull"-style model view control (MVC), where the view pulls data from components as it is being rendered rather than using action listener methods to retrieve and prepare data for the view.
1.9.1. Using "pull"-style MVC 复制链接链接已复制到粘贴板!
复制链接链接已复制到粘贴板!
This snippet from the
index.xhtml
facelets page displays a list of recent blog entries:
If we navigate to this page from a bookmark, the
#{blog.recentBlogEntries}
data used by the <h:dataTable>
is retrieved lazily — "pulled" — when required, by a Seam component named blog
. This flow of control is the reverse of that used in traditional action-based web frameworks like Struts.
Example 1.34.
This component uses a seam-managed persistence context. Unlike the other examples we've seen, this persistence context is managed by Seam, instead of by the EJB3 container. The persistence context spans the entire web request, allowing us to avoid any exceptions that occur when accessing unfetched associations in the view.
| |
The @Unwrap annotation tells Seam to provide the return value of the method — the Blog — instead of the actual BlogService component to clients. This is the Seam manager component pattern.
|
This will store basic view content, but to bookmark form submission results like a search results page, there are several other required definitions.