You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Sam Zilverberg <sa...@gmail.com> on 2009/09/16 16:33:47 UTC

dropdownchoice selection problem after pressing the wizard previous button

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);
        }
    }

Re: dropdownchoice selection problem after pressing the wizard previous button

Posted by Sam Zilverberg <sa...@gmail.com>.
I have another DDC in the wizard that works properly, it shows the correct
value when using the wizard previous button.
It's connected to the "deviceType" property of Device and gets its choices
from an enumeration I have.

            add(new DropDownChoice("deviceType",
Arrays.asList(DeviceType.values())));

The only difference I can find between this DDC and the one that doesn't
work is where the choices come from.
The DDC that doesn't work gets its choices from the db (through a
LoadableDetachableModel).

On pressing previous I see (with the help of prints) that the DDC holds the
correct model value, that is the one i chose before, but it just wont disply
it!!

any ideas?

Re: dropdownchoice selection problem after pressing the wizard previous button

Posted by Sam Zilverberg <sa...@gmail.com>.
deviceCreation is defined only once in the wizard class.

all of the wizard steps are inner classes and, if needed, refer to
deviceCreation of their outer class which is the main wizard class.

so it should be the same instance.

On Wed, Sep 16, 2009 at 6:26 PM, Pedro Santos <pe...@gmail.com> wrote:

> 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
>
>
>

Re: dropdownchoice selection problem after pressing the wizard previous button

Posted by Pedro Santos <pe...@gmail.com>.
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 <sa...@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);
>        }
>    }
>