On Mon, 23 Jun 2008, Giuliano Caliari wrote:
> When the user sets the value on the first DDC, the value of the second DDC
> is set without problems, even the selected value is set correctly.
> The problem is that if the user changes the value on the first DDC
> (mapCategory) and then submits, the value passed on the second DDC
> (chosenArmy) is always "null", so the value received by "stwMatchPrefs" is
> null.
Hi,
I haven't completely understood what is happening here, but
will try to give some ideas below.
There is something strange happening with the models there.
Have you read the models wiki page?
You could also try removing PropertyModel and
CompoundPropertyModel usage for now, because they might
obfuscate the problem.
> IModel armyChoices = new AbstractReadOnlyModel()
> {
> public Object getObject()
> {
> List<Army> armys = new ArrayList<Army>();
> armys.add(stwData.getArmyByCategory(StwMapCategory.SMALL));
> armys.add(stwData.getArmyByCategory(StwMapCategory.MEDIUM));
> armys.add(stwData.getArmyByCategory(StwMapCategory.LARGE));
>
> stwMatchPrefs.setChosenArmy(stwData.getArmyByCategory(stwMatchPrefs.getMapCategory()));
> return armys;
> }
> };
This seems like a strange side effect -- whenever a component
with armyChoices as its model is rendered,
stwMatchPrefs.setChosenArmy() is called. Because this is the model
of the chosenArmy DropDownChoice, whenever the DropDownChoice is
rendered, this getObject() method is evaluated. But then again
> final DropDownChoice chosenArmy = new DropDownChoice("chosenArmy",
> new PropertyModel(stwMatchPrefs, "chosenArmy"), armyChoices,
> armyChoicesRenderer );
> chosenArmy.setOutputMarkupId(true);
> stwPrefsForm.add(chosenArmy);
>
> mapCategory.add(new AjaxFormComponentUpdatingBehavior("onchange")
> {
> protected void onUpdate(AjaxRequestTarget target)
> {
>
> stwMatchPrefs.setChosenArmy(stwData.getArmyByCategory(stwMatchPrefs.getMapCategory()));
> chosenArmy.setModelObject(stwMatchPrefs.getChosenArmy());
> target.addComponent(chosenArmy);
> }
> });
> }
Here you give a PropertyModel to chosenArmy DropDownChoice,
and it operates directly with the "chosenArmy" property of
stwMatchPrefs. This means that the chosenArmy DropDownChoice
selection and stwMatchPrefs.chosenArmy property are bound to
each other: when one changes, the other one changes as well.
In this light, it is absurd that you change both values in
the onUpdate method. stwMatchPrefs.setChosenArmy() should be
enough.
What is even stranger is that because of the armyChoices
model, stwMatchPres.setChosenArmy() is getting a competing
call during rendering :)
> public ArmyServices getArmyServices() {
> return armyServices;
> }
>
> public void setArmyServices(ArmyServices armyServices) {
> this.armyServices = armyServices;
> }
BTW, what are these methods here for?
Best wishes,
Timo
--
Timo Rantalaiho
Reaktor Innovations Oy <URL: http://www.ri.fi/ >
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]