You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Viktor Micskó <vi...@micsko.com> on 2016/01/27 09:25:19 UTC

TextField updated via AJAX not sent in form?

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

Re: TextField updated via AJAX not sent in form?

Posted by Martin Grigorov <mg...@apache.org>.
Hi,

Wicket behaves the same way in both cases.
It is just that the browser doesn't send request parameter for "price" when
the HTML is invalid. That's why it is null at the server side.

Martin Grigorov
Wicket Training and Consulting
https://twitter.com/mtgrigorov

On Wed, Jan 27, 2016 at 11:13 PM, Viktor Micskó <vi...@micsko.com> wrote:

> Hi,
>
>
> Thank you, this was the reason indeed.
>
> Just for the archive: forms in tables seem to work fine as long as you
> don't update form fields via AJAX, but Labels are updated correctly.
>
>
> Kind Regards,
> Viktor Micsko
>
> On Wed, Jan 27, 2016 at 9:33 AM, Thomas Matthijs <li...@selckin.be> wrote:
>
> > > 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.
> >
> > <form> is not allowed to be in table, see
> > https://developer.mozilla.org/en/docs/Web/HTML/Element/table
> >
> > You are still building html, it has to be (mostly) valid
> >
> > Kind regards
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> > For additional commands, e-mail: users-help@wicket.apache.org
> >
> >
>

Re: TextField updated via AJAX not sent in form?

Posted by Viktor Micskó <vi...@micsko.com>.
Hi,


Thank you, this was the reason indeed.

Just for the archive: forms in tables seem to work fine as long as you
don't update form fields via AJAX, but Labels are updated correctly.


Kind Regards,
Viktor Micsko

On Wed, Jan 27, 2016 at 9:33 AM, Thomas Matthijs <li...@selckin.be> wrote:

> > 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.
>
> <form> is not allowed to be in table, see
> https://developer.mozilla.org/en/docs/Web/HTML/Element/table
>
> You are still building html, it has to be (mostly) valid
>
> Kind regards
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>

Re: TextField updated via AJAX not sent in form?

Posted by Thomas Matthijs <li...@selckin.be>.
> 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.

<form> is not allowed to be in table, see
https://developer.mozilla.org/en/docs/Web/HTML/Element/table

You are still building html, it has to be (mostly) valid

Kind regards

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org