Learning Spring (3.1.0) and Hibernate (4.1.1). Just wondering what most developers do when handling form data. When writing a JSP that contains a form used to submit data, do you normally write a class specific to the input fields on that form and process that server-side or do you just use your entity classes and bind them to the elemtns on the form?
Say I have an application that has 3 entity classes: Location, StoreType and Store (a Store has a StoreType and a Location). On the form on the /CreateStore JSP page I have a dropdown select box with all Locations, another dropdown select box with all the StoreTypes and other text input fields with store name, store manager etc.
Do you create a CreateStoreForm class with a List locationNames, List storeTypes, String storeName etc. and put this on the model? Or do you just put all the various entity classes on the Model separately? I have been using the latter approach but I am thinking that the former may be better especially for re-populating the screen when a user makes consecutive requests to the same screen.
It’s always good to have a class that maps form, then write a util method which converts from form class to the actual model class which Hibernate would be using to do operations.
And for the drop-down, you can use
@ModelAttributeon a method separately which returns the list and which you will be able to use in form. And you won’t need to add it to your form class or entity class.