简体   繁体   中英

preserving component state across multiple request cycles

Question about component state management with Apache Wicket 1.4.x

I have a bookmarkable, stateful page that contains a form with a set search criteria. The user search for items matching the selected criteria and then navigate away from the page (to a detailed item view, for instance). At some point of time the user can come back to the search page using a bookmarkable link. I would like the last search criteria to be pre-selected as a default choice. However, it appears that BookmarkablePageRequestTarget aways creates a new instance of the target page in its #respond(RequestCycle) method, thus losing previous state (the bean backing the search form).

Naturally, I could manually manage the form state and store it in the WebSession subclass, but I am wondering whether or not there might be a better way to preserve component state across multiple request cycles, like making Wicket re-use the existing instance of the target Page? Ideally this would work with bookmarkble links.

Normally, the state of a component is stored in the component instance itself. (Either directly in it, or indirectly, in models.)

So all you really need to do is to create a link that points to the search page instance , or call setResponsePage() with the page instance or something similar, depending on how you're redirecting the user.

Normally, you shouldn't even touch request targets at all, unless the actual scenario is much more complex than the one you're describing.

Mount your bookmarkable page with HybridUrlCodingStrategy or its subclass. This will append a page identifier to the URL and ensure that the back button works with bookmarkable links.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM