Hi,

It looks
like org.apache.wicket.markup.html.form.FormComponent#updateModel() is not
called for the FormComponentPanel.
Usually this happens when there is an error in the validation. But since
#onSubmit() is called then the validation should have been passed,
otherwise #onError() should have been called.

Put a breakpoint at
https://github.com/apache/wicket/blob/master/wicket-core/src/main/java/org/apache/wicket/markup/html/form/Form.java#L913
and see whether it goes down to
https://github.com/apache/wicket/blob/master/wicket-core/src/main/java/org/apache/wicket/markup/html/form/Form.java#L945

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

On Thu, Dec 18, 2014 at 12:14 AM, Andreas Lundblad <
[email protected]> wrote:
>
> I'm experiencing the strangest behavior with a FormComponentPanel.
>
> My custom FormComponentPanel has the following method:
>
>     @Override
>     protected void convertInput() {
>         CountryImpl c = new CountryImpl(countryId,
>                                         name.getConvertedInput(),
>                                         currency.getConvertedInput(),
>                                         flag.getConvertedInput());
>         System.err.println("Setting converted input: " + c + " (identity: "
> + System.identityHashCode(c) + ")");
>         setConvertedInput(c);
>     }
>
> Upon form submission I get the following printout on System.err:
>
> Setting converted input: CountryImpl[id: 53b2c7a0986c5f4527783d16, name:
> Sweden, currency: SEK, flag: ImageImpl[id=543d4328e4b0524ccbf143f8,
> data.length=13452]] (identity: 1113118053)
>
> Which is exactly what I expect. Great. Now to the part I can't explain:
>
> In the Form that encloses this FormComponentPanel, I have the following
> code:
>  (
>             @Override
>             public void onSubmit() {
>                 Country country = countryPanel.getModelObject();
>
>                 System.err.println("country from
> countryPanel.getModelObject(): " + country + " (identity: " +
> System.identityHashCode(country) + ")");
>                 ...
>             }
>
> And upon submit I get the following output:
>
> country from countryPanel.getModelObject(): CountryImpl[id:
> 53b2c7a0986c5f4527783d16, name: Sweden, currency: SEK, flag: ImageRef[id:
> 543d4328e4b0524ccbf143f8]] (identity: 1025123013)
>
> As you can see, the countryPanel.getModelObject() does not match the object
> that I used in setConvertedInput! (By looking at the
> System.identityHashCode one can see that they are not the same object.) Why
> is this? This is how I've always done!
>
> Other (strange) observations:
>
> - If I change one of the text-fields (name or currency) it works as
> expected! I get the same object out from getModelObject as I give to
> setConvertedInput
> - If I instead of countryPanel.getModelObject() do
> countryPanel.getConvertedInput() I get the expected object. (In [1]
> however, it says I should use getModelObject()
>
> I've stepped through the Wicket form processing code but it's really
> complex and I can't determine where it goes wrong. I have other custom
> components (seemingly identical to the CountryPanel) that works as
> expected.
>
> Any suggestions on what may be the issue is welcome. (I would hook you up
> with a minimal test case if I could, but I can't reproduce this when
> writing from scratch. Some detail seems to evade me.)
>
> best regards,
> Andreas Lundblad
>
> [1]
>
> https://cwiki.apache.org/confluence/display/WICKET/Creating+Custom+FormComponentPanel%27s+to+build+valid+objects+using+Wicket%27s+Form+Validation+Logic
>

Reply via email to