wicketwicket-1.5wicket-1.6

Wicket: access field from inner form


I have a Wicket page with this structure:

<form wicket:id="generalForm" method="post" class="form_recherche">
        <input value="" type="text" wicket:id="myField_1" />

        <form wicket:id="innerForm" method="post">
                <input value="" type="text" wicket:id="myField_2"/>
                <input type="submit" class="button-classic" wicket:id="accept_2"/>
        </form>

        <input type="submit" class="button-classic" wicket:id="accept_1" /> 

</form>

1 external form with 1 inner form. One field each. The fact is that when the "accept_2" button is clicked, the field "myField_1" is not submitted to the server (only the "myField_2" is submitted). And in fact, I would need the "field_1" field to do some validation.

What am I missing and why isn't the "myField_1" being filled on the server why "accept_2" is clicked?


Solution

  • You need to override Form#wantSubmitOnNestedFormSubmit() on the outer Form to return true. This way you will tell Wicket that you want the (outer) form to be submitted as well when one of its nested forms is submitted.

    You used SO tags wicket-1.5 and wicket-1.6. I am not sure whether this method is available for your version of Wicket.