Dynamically determine the content of a *WizardStep* during runtime

Ok so I have been tinkering a bit with the Wizards for Vaadin addon. I managed to create a wizard that gets loaded into my view and all the steps within it. Now I have an issue however.

I am using different layouts, which I then load into my wizardSteps, such as e.g this:

public class Step2 implements WizardStep{  

.... 
@Override
    public Component getContent() {
        Layout2 = new Layout2(model, wizard.getPlanes());
        return Layout2;
    }
....
}

This is working as intended, it fills the content of my
step2
with the
Layout2
and so forth…

Now, however what I am trying to achieve is the following:

I want to use a variable, that I get after completing
step1
… how do I achieve this? I wanted to do this via the onAdvance() method, but somehow this does not seem to work. When I check using the Debugger, I can see that prices is still empty (this means that at that time, the prices I selected via OptionGroup are still empty)

public class Step1 implements WizardStep{   

String planes;
.... 
@Override
    public Component getContent() {
        Layout1 = new Layout1(odel);
        return Layout1;
    }
....
//I'm checking all optionGroups in Layout1 (have multiple for other reasons) and if they are selected,
//I can continue to the next step

    public boolean onAdvance() {
        for(OptionGroup optionGroup : Layout1.getOptionGroups()){
            
            if(optionGroup.getValue() != null){
                planes = getPlanes();
                wizard.setPlanes(planes);
                return true;
            }    
        }
    }
}

Hi,

while I am not 100% sure what you want to accomplish the following code might be of use. Please note that what you want to do can probably be achieved in a number of different ways and this might not be the fastest way but in my example it works fine.

I initialize the wizard and add two steps, such that the second step gets the first step as a parameter:

Wizard myWizard = new Wizard();
FirstStep firstStep = new FirstStep();
myWizard.addStep(firstStep);
myWizard.addStep(new SecondStep(firstStep));

The FirstStep class looks like this:

public class FirstStep implements WizardStep {

    TextField text;

    @Override
    public String getCaption() {
        return "1Step1";
    }

    @Override
    public Component getContent() {

        VerticalLayout layout = new VerticalLayout();
        layout.setMargin(true);
        layout.setSpacing(true);

        text = new TextField();
        layout.addComponent(text);

        return layout;
    }

    @Override
    public boolean onAdvance() {
        return true;
    }

    @Override
    public boolean onBack() {
        return true;
    }

    public String getInputValue() {
        if (text == null || text.getValue() == null) {
            return "";
        }
        return text.getValue();
    }

}

Thus in the second step I need the constructor:

    FirstStep firstStep;

    public SecondStep(FirstStep firstStep) {
        this.firstStep = firstStep;
    }

Which allows me to use this code, also in the second step:

    @Override
    public boolean onAdvance() {
        if (firstStep.getInputValue().equals("Continue")) {
            return true;
        }
        return false;
    }

Hopefully this example will help you modify your code in the desired way.

Best regards,

Henrik