The device on wizard model need to be the same instance that was passed to
the DropDownChoice?
See if at some point you are working with 2 intances of Device.

new PropertyModel<Distributor>(devicesCreation, "distributor"),
 private Device deviceCreation;

devicesCreation != deviceCreation


On Wed, Sep 16, 2009 at 11:33 AM, Sam Zilverberg <samzilverb...@gmail.com>wrote:

> I'm using a wizard with a CompoundPropertyModel of some object called
> Device.
> The Device object has a distributor and company properties (and some other
> too...)
>
> In the first step of the wizard, the user has to choose a distributor or
> company(both allowed too) for this device.
>
> For the device's distributer selection I have a DropDownChoice that uses a
> PropertyModel.
> I've also setNullValid to true and provided a properties key for the null
> value.
>
> The problem is that after I choose a distributor, go to the next step, and
> then return, the distributor I chose before is not automaticaly chosen in
> the DDC, instead the
> first value in the choices list is chosen (null value in this case).
>
> I've overridden afterRender and onModelChange for debug purposes.
> I've added a simple console print that prints out the Device.distributor
> value and the DDC defultObjectModel value.
>
> From these prints, I've gathered that after pressing previous, the DDC
> holds
> the correct chosen value for distributor but it doesnt display it.
>
> some more info:
> The DDC is in an inner form along with a custom panel for choosing a
> company.
> I didn't define a model for this form.
> I use this form to hold both the distributor and company selection so that
> i
> can validate that either (or both) was chosen.
>
> some relevant code:
>
> the wizard class has
>    private Device deviceCreation;
>
> and in its constructor
>        setDefaultModel(new CompoundPropertyModel<Device>(deviceCreation));
>
> the inner InfoStep class (the first step in the wizard):
>
> private final class InfoStep extends WizardStep {
>
> public InfoStep() {
>
>            add(new DropDownChoice("devicesType",
> Arrays.asList(DeviceType.values())));      <<<< this is another DDC for
> another property that does work properly!!
>
>            final DropDownChoice<Distributor> distribChoice =
>                    new DropDownChoice<Distributor>("distributor",
>
> new PropertyModel<Distributor>(devicesCreation, "distributor"),
>
> new DistributorModel(distributorDao)) {
>                @Override
>                protected boolean wantOnSelectionChangedNotifications() {
>                    return true;
>                }
>            };
>
>            distribChoice.setNullValid(true);
>
>            final CompanyChooser compChoose = new CompanyChooser("company");
>
>            Form form = new Form("distribOrCompanyForm") {
>
>                // perform custom validation
>                // check that either a distributer or a company was chosen
> (or
>                // both)
>                @Override
>                protected void onValidate() {
>                    super.onValidate();
>                    if (distribChoice.getModelObject() == null  &&
> !compChoose.isValid()) {
>                        this.error("distributer or company selection is
> required");
>                    }
>                }
>
>            };
>            add(form);
>            form.add(distribChoice);
>            form.add(compChoose);
>        }
>    }
>

Reply via email to