Search code examples
spring-bootmodel-view-controllerbootstrap-typeahead

Form management with Springboot - autofill a form when user select a typeahead


I have a spring-boot, MVC, web application form. The user can type and object name in a field. This field got a bootstrap typeahead dynamique list of already existing objects.

I'd like to autofill my form's ohterfields with several object attribute when the user select a known object in the typeahead list.

My question is, in a correct implementation of MVC in springboot, how should this be done? How to tell my controller "Hey the user selected -foo- object, fill the other fields now!" ? Should it be a POST of the form? Is there a kind of @heyFillTheForm to put in the controller?

Thank you


Solution

  • From a design point of view, I'd indeed POST or PUT those parts of the form using an XHR.

    However, I think would create two separate MVC controller methods:

    1. One called retrieveAutofillValues, returning a JSON-object with the prefill values. One might argue this should be a PUT
    2. one POST called submitForm, returning the result of the submit