Rob Benton
Rob Benton

Reputation: 477

Apache Wicket: Updating multiple FormComponents with a single ajax request

The wicket form process exeuctes the conversion, validation, and model updates for all FormComponents in a form. The AjaxFormComponentUpdatingBehavior will perform this process for a single component. What I am looking for is a way to use an event on one FormComponent to execute the form processing for two FormComponents.

An example page might look like this:

    <form wicket:id='form'>

        <label>Name</label>
        <input type='text' wicket:id='name'/>

        <label>Start Date</label>
        <input type='text' wicket:id='start'/>

        <label>End Date</label>
        <input type='text' wicket:id='end'/>

    </form>

When one of the date fields is changed I want to validate it, using ajax, against the other and update both models leaving all other components on the form alone. To do this the conversion, validation, and model updates must happen on both fields. I haven't found a way to do this using a single ajax event.

Any ideas?

Upvotes: 2

Views: 425

Answers (1)

Andrea Del Bene
Andrea Del Bene

Reputation: 2511

probably the most straightforward way to solve your problem is wrapping your 2 fields in a nested form:

 <form wicket:id='form'>

    <label>Name</label>
    <input type='text' wicket:id='name'/>
       <form wicket:id='innerForm'>
         <label>Start Date</label>
         <input type='text' wicket:id='start'/>
         <label>End Date</label>

         <input type='text' wicket:id='end'/>
       </form>
</form>

Than one of the date fields change just submit via AJAX (with a AjaxFormSubmitBehavior) the innerForm and apply you validation logic to the two fields. Hope this could help you.

Upvotes: 3

Related Questions