Quick revision
The short answer
I would separate form models from domain models, with one form class per screen or wizard step, explicit mapping to the domain, and validation groups per step. Then I would standardise the repeated parts: error messages, error rendering fragments and naming of indexed properties like items[0].qty. Wizard state would live in a clearly scoped session form object or a server-side draft record, the most interactive screens may move to Vaadin or an SPA, and the whole change goes form by form behind end-to-end tests.
What to remember
In this answer, we saw that form-heavy Spring MVC applications decay mostly because forms, validation and persistence share one model. Separate form classes with explicit mapping and validation groups fix that. Shared fragments, messages and conventions for indexed properties remove repeated code, wizard state belongs in an explicit session object or a draft record, the most interactive screens may move to Vaadin or an SPA, and the migration goes form by form behind end-to-end tests.
Your turn
Answer it aloud as you would in the interview, or type your answer below. Then show one part at a time and compare.
I would separate form models from domain models, with one form class per screen or wizard step, explicit mapping to the domain, and validation groups per step. Then I would standardise the repeated parts: error messages, error rendering fragments and naming of indexed properties like items[0].qty. Wizard state would live in a clearly scoped session form object or a server-side draft record, the most interactive screens may move to Vaadin or an SPA, and the whole change goes form by form behind end-to-end tests.
Why this question is asked
Back-office applications are where server-rendered forms are at their best and their worst. Hundreds of screens get built fast, and ten years later every screen does binding, validation and error display a little differently. When an interviewer asks how to modernise this, they want to hear a plan that lowers the defect rate without a big-bang rewrite. In this answer, we will look at why these forms decay, then go through the changes in the order I would make them: separate form models, shared conventions for nested and indexed fields, explicit wizard state, a decision on which screens should leave server rendering, and a safe migration path.
1Why Forms Like These Become Slow to Change
Spring MVC data binding maps request parameters onto an object graph. A parameter called order.lines[3].quantity means: take the order, take its lines list, take element 3, set its quantity. This is powerful, and in older applications it was often used straight onto JPA entities. The form, the validation and the database model then share one class.
That sharing is the root of most bugs. A validation rule added for one screen breaks another screen that binds the same entity. A dynamic row removed in the browser leaves a gap in the index, so the list on the server holds a null element. Wizards carry the whole object in hidden fields from step to step, and any field someone forgot to add as hidden is lost. Each problem is small, but together they make every change slow, because nobody can tell what a form really binds.
2Separate Form Models From Domain Models
The first change is to give each screen its own form model, a plain class or record shaped like the screen, not like the database. A mapper, written by hand or with MapStruct, copies the form onto the domain in the service layer. Validation lives on the form, and for wizards we use validation groups, marker interfaces that let us validate only the fields of the current step.
Notice that @Validated, Spring's variant of @Valid, accepts groups, so step 2 does not fail on a rule that belongs to step 3. The domain object is only built once all steps pass, in one service call, so the database never sees a half-filled order.
3Standardise the Repeated Parts
Most of the code in a form-heavy application is the same work repeated: render an input with its label, show its errors, keep the value after a failed submit. We should write that once. With Thymeleaf, a shared fragment does it, and every screen calls the fragment instead of copying markup.
The same goes for messages: one messages.properties with keys like NotBlank.orderForm.customerCode, so wording is consistent and translatable. For dynamic rows, we agree on one rule, for example that the browser always renumbers the rows from zero before submitting, or that the server compacts the list and drops empty rows. Either is fine; mixing them across screens is what causes the null-element bugs.
4Keep Wizard State Explicitly
A wizard needs somewhere to keep the answers from earlier steps. Hidden fields work for two small steps, but with eight steps they send the whole object back and forth and trust the browser with it. Two better options exist, and we choose per wizard.
| Option | Good for | Cost |
|---|---|---|
| Hidden fields | Two short steps | Everything round-trips; easy to lose or tamper with fields |
| Session form object | Short wizards, one sitting | Lost on expiry; needs sticky or shared sessions |
| Server-side draft record | Long or important wizards | A table, cleanup of old drafts, more code |
The first option is a session-scoped form object, for example with @SessionAttributes("orderForm") on the controller and SessionStatus.setComplete() on the last step, so the lifecycle is visible in code. It is simple, but the state is lost if the session expires and it needs sticky sessions or a shared session store such as Spring Session with Redis. The second option is a server-side draft record: each step saves to a drafts table with a status, and the URL carries the draft id. It costs a table and a cleanup job, but users can leave and come back tomorrow, and support staff can see where someone got stuck. For long or business-critical wizards, the draft record is usually worth it.
5Decide Which Screens Should Leave Server Rendering
Not every screen should stay a server-rendered form. A grid where users edit fifty rows with live totals, drag rows around and see dependent fields change is painful with full page posts. For those few screens, a component UI is a better fit. Vaadin lets the same Java team build rich components on the server, and an SPA with a JSON API suits teams with front-end skills. Small doses of htmx or Thymeleaf fragments can also refresh one part of a page without a rewrite.
The point is to choose per screen, based on how interactive it is. Most back-office forms, a few fields and a save button, are fine server-rendered, and moving them would add an API layer and a build chain for no gain.
6Migrate Form by Form Behind Tests
Before changing a critical form, we capture its current behaviour with an end-to-end test, for example with Playwright or Selenium, that fills the form, submits it and checks the saved result, including one failing validation. Then we refactor that form alone: new form class, shared fragments, explicit mapping. The test tells us we did not change behaviour by accident.
I would order the work by pain: start with the ten forms that have the most bug reports or the most change requests, because that is where the effort pays back first. A simple tracking page with the forms migrated so far keeps the team and managers honest about progress, and new screens follow the new conventions from day one.
7Follow-up questions
Would you use MapStruct or hand-written mappers?
Either works. MapStruct generates the copying code at compile time and reports unmapped fields, which helps with large forms. Hand-written mappers are easier to read for small forms and for mapping that has logic in it. What matters is that the mapping is explicit and lives in one place per form, not that it uses a particular tool.
How do you protect against mass assignment in nested forms?
Form classes only contain editable fields, so there is nothing else to bind. On top of that, an @InitBinder with setAllowedFields can use patterns like lines*.quantity for indexed paths. The ids of existing rows should be checked in the service against what the user may edit, never trusted blindly from the request.
8Conclusion
In this answer, we saw that form-heavy Spring MVC applications decay mostly because forms, validation and persistence share one model. Separate form classes with explicit mapping and validation groups fix that. Shared fragments, messages and conventions for indexed properties remove repeated code, wizard state belongs in an explicit session object or a draft record, the most interactive screens may move to Vaadin or an SPA, and the migration goes form by form behind end-to-end tests.
Open with
I'd start by finding out why maintenance is slow, and in apps like this it's usually that forms bind straight onto domain or JPA objects, so validation rules, persistence and screens are all tangled together.
Then, if they want more
So the core change is a form model per screen or per wizard step, with explicit mapping into the domain in the service layer, and validation groups so each step only checks its own fields.
Then I'd standardise the repeated parts: one Thymeleaf fragment for a field with its label and errors, one messages file, and one agreed rule for dynamic rows, so indexed paths like items[0].qty never leave gaps. For wizards, I'd stop carrying everything in hidden fields.
Short wizards get a session-scoped form object with a clear start and end, long ones get a server-side draft record so users can come back later. I'd also look at which screens are really interactive, like big editable grids, and consider Vaadin or an SPA just for those, keeping simple forms server-rendered. Finally, I wouldn't rewrite everything.
I'd put end-to-end tests around the critical forms first, then migrate form by form, starting with the ones that generate the most bugs.
About this answer
- Last updated
- 12 November 2026
- Checked
- Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
- Where the question comes from
- Written by Scrivio for practice. It is not taken from an interview.
- Official documentation
- Spring Framework reference, Spring Web MVC
Report an issue with this answer
Copy the line below and send it to the author with what you found. It carries the address of this page.
Issue with "A large internal back-office application has hundreds of server-rendered forms with...": https://scrivio-interview-library.netlify.app/spring-boot/mvc-architecture/e32ee96467/