demarcating conversations with Wicket-CDI
-
09-12-2019 - |
Question
I'm using Wicket-CDI to integrate CDI with Wicket. I have a multi-page "wizard" flow, in which the user completes various forms using a bean that's marked with @ConversationScoped
.
The flow works fine, but I can't figure out how to "reset" the bean when I explicitly end the conversation. I have a "start over" link that does:
public void onClick() {
conversation.end();
setResponsePage(WizardFlowPage1.class);
}
I've verified that my page constructor is called and that the conversation gets a new cid, but the conversational bean that gets injected is the same instance as the previous flow (with all the fields retaining their previous values).
A simple fix is to add a reset()
method to the bean and reset the fields, but this seems like a hack (and prone to error if I later add a new field).
How can I convince CDI/Weld to create a new instance of the conversational bean when the conversation is ended?
Solution
It turns out that my conversation bean had some fields that were missing getters & setters. Wicket's PropertyModel allows you to get away with this as a convenience.
Adding the getters & setters made it conform to JavaBean conventions, and allowed CDI to properly do its thing.