NOTE: This issue may or may not be Vaadin related, depending on wether there is a "better" solution to "resetting" the bean or not.
Background scenario
I am building a wizard for entering some values that, when finished, is sent to a table (using Vaadin and the add-on "Wizards for Vaadin").
The add-on does not provide a way to reset the Wizard (i.e. go back to step 1) without a forced call to the current steps (overridden) onAdvance() and onBack() methods, which will return false in some of my steps because I'm using logic in those methods in case the use for example haven't filled in all required data.
I cannot simple create a new instance of the Wizard, because I'm using Spring to manage this @Component.
So, this leaves me with actually resetting the bean in order to reset the wizard correctly.
My question is
How do I "reset" a Spring managed Bean (@Component)? I should add that this Bean also has some dependencies injected to it.
or... (for the Vaadin people):
Is there another way of resetting this wizard other than creating a new Wizard?
Some code
@Component
@Scope("session")
public class MyWizard extends Wizard {
@Inject
private MyWizardContainer myWizardContainer;
@Inject
private MyService myService;
@Inject
private MyWizardStep1 myWizardStep1;
@Inject
private MyWizardStep2 myWizardStep2;
@Inject
private MyWizardStep3 myWizardStep3;
@Inject
private MyMainTableContainer myMainTableContainer;
final static Logger logger = LoggerFactory.getLogger(MyWizard.class);
private static final long serialVersionUID = 1L;
public MyWizard() {
setupListener();
}
public void addSteps() {
this.addStep(myWizardStep1);
this.addStep(myWizardStep2);
this.addStep(myWizardStep3);
this.mainLayout.setComponentAlignment(this.footer, Alignment.BOTTOM_LEFT);
}
private void setupListener() {
this.addListener(new WizardProgressListener() {
@Override
public void wizardCompleted(WizardCompletedEvent event) {
endWizard("Wizard Finished Successfully!");
}
@Override
public void wizardCancelled(WizardCancelledEvent event) {
endWizard("Wizard Cancelled!");
}
@Override
public void stepSetChanged(WizardStepSetChangedEvent event) {
// TODO Auto-generated method stub
}
@Override
public void activeStepChanged(WizardStepActivationEvent event) {
// TODO Auto-generated method stub
}
});
}
private void resetWizard() {
myWizardContainer.removeAll(); //here I'm simply resetting all data that the user generated thus far in the wizard
this.activateStep(myWizardStep1); //this will not work, as some steps will not always return true on onBack() and/or onAdvance()
}
private void endWizard(String message) {
resetWizard();
this.setVisible(false);
Notification.show(message);
}
}