Hi,
I found an interesting behavior, which finally I avoided in this project
due to changing requirements, but it still bothers me, so I thought I'd ask
anyways, perhaps I'm missing something trivial.
The basic idea is that there is list of sales data in a table (think of it
like a sales receipt), with a form having a list of products to add in a
DropDownChoice, and a price in a TextField. Each product has a default
price, which the user can accept or enter another one (e.g. discounts): you
choose a product in the DropDownChoice, its default price gets populated
into the TextField via AJAX, and then the user may or may not change this
price before submit.
So the DropDownChoice has an AjaxFormComponentUpdatingBehavior("change")
which calls target.add(priceField).
I uploaded a quickstart here: http://micsko.com/example.zip
This is what I found:
o) The problem is that if I choose a product first, and then enter a
different price, the model object of the TextField will be null, not the
default nor the entered price. It seems like the browser doesn't even send
the price field in the form, but it does send the product field. After
submit the TextField will be reset to empty, this seems to be correct given
that the model object is now null for some reason. If I enter another value
and submit the form again, the price is now being sent. But not on the
first submit.
o) If, on the other hand, I don't choose a product, just enter a price,
then the model object of the TextField will contain the entered value, as
expected.
o) For this behavior to happen, it's not even required to change the price
model object, it's enough that I add the TextField to the AjaxRequestTarget
(see PriceForm.java line 71).
o) I also found that this only happens when the markup looks like this,
i.e. the form is inside the table (See HomePage.html):
<table>
<form wicket:id="form">
...
</form>
</table>
...but not when the form is outside (see WorkingPage.html)
<form wicket:id="form">
<table>
...
</table>
</form>
The first markup would be preferred so that the existing values line up
nicely with the form fields.
Any ideas what I'm missing?
Thanks,
Viktor Micsko