Reputation: 27518
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.
Upvotes: 1
Views: 490
Reputation: 3682
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.
Upvotes: 0
Reputation: 49714
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.
Upvotes: 1