Back Forum Reply New

spring simpleFormController form submission

Hello,

I've a small doubt. I use Spring SimpleFormController with a form backing object.

Let's say my formBackobject has the following member:- Id- Name- Sex

on the jsp page, I only bind name and sex to input field. when i submit the form, the backend controller can remember the value of the id field and so can distinguish whether this is a quot;newquot; or quot;edit' mode.

Could you tell me the trick behind this?Thanks,

Usually you will have 2 controllers, 1 for edit and 1 for add.
The Add controller will create a new form backing object (no ID). The Edit controller will retrieve an existing object from the DB (ID is present.)
If you want 1 controller for edit and add operations, you'll need to write down the logic for the above decision.
The creation of the ID is usually automatic and is left to the DBMS with the help of hibernate or other ORM.
the fields you need to bind are only those a user needs to input. The others (e.g. ID) should be filled in before you show the form.
¥
Back Forum Reply New