Wicket Wizard gives false information in method is

2019-08-18 03:18发布

问题:

in addition to a previous question, I'm trying to do my own implementation of a Wicket Wizard with a step overview. Now the problem is, that isComplete(); seems to return true, even if the step hasn't been finished. I made 3 wizardsteps and then I'm running this code:

public class MainWizard extends Wizard{
    private static final long serialVersionUID = 1L;
    private List<IWizardStep> steps = new ArrayList<IWizardStep>();
    private Component overview = newOverviewBar("overview");
    private IWizardModel wizardModel;

    public MainWizard(String id, IWizardModel wizardModel, boolean addDefaultCssStyle) {
        super(id, wizardModel, addDefaultCssStyle);
        this.wizardModel = wizardModel;
        fillList();
        getIndex();
        this.add(overview);
    }

    public void getIndex(){
        for(IWizardStep step : steps){
            System.out.println(step.getClass());
            if(step.equals(wizardModel.getActiveStep())){
                System.out.println("Active");
            } else if(!step.isComplete()){
                System.out.println("Pending");
            } else if(step.isComplete()){
                System.out.println("Finished");
            }
        }
    }

    public void fillList(){
        Iterator<IWizardStep> iterator = wizardModel.stepIterator();
        while(iterator.hasNext()){
            steps.add(iterator.next());
        }   
    }

    @Override
    public void onActiveStepChanged(IWizardStep newStep) {
        try{
            getIndex();
        } catch (Exception e){
            e.getMessage();
        }
        super.onActiveStepChanged(newStep);
    }
}

The output in the console for the first step is:

class {package}.StepOne > Active
class {package}.StepTwo > Finished
class {package}.StepThree > Finished

On change to the next step:

class {package}.StepOne > Finished
class {package}.StepTwo > Active
class {package}.StepThree > Finished

On the last step:

class {package}.StepOne > Finished
class {package}.StepTwo > Finished
class {package}.StepThree > Active

I can't explain this behaviour. As in the post I linked above suggested, I would like to share this component if it works at the end. Thanks in advance.

Is it a problem, that the steps I implemented don't have a real goal yet? Do I have to manually set setComplete(); or whatever it is in my code for the panels?

回答1:

The meaning of IWizardStep#isComplete() is not what you think it is:

/**
 * Checks if this step is complete. This method should return {@code true} if the wizard can
 * proceed to the next step.
 * 
 * @return {@code true} if the wizard can proceed from this step, {@code false} otherwise.
 */
boolean isComplete();

Take note of "if the wizard can proceed to the next step".