Spring SimpleFormController form submission
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 "new" or "edit' mode.
Could you tell me the trick behind thi开发者_StackOverflows?
Thanks,
In my opinion you need to override isEqual() and hashCode() function.
In my code I'm generating uuid and assign it to String and then implement isEqual() and hashCode() where I'm comparing these strings.
Such technique is very useful for Hibernate as well and it will assure you that you always generate unique object.
The 'trick' behind is that the form is kept in session. When you submit the form, only 'name' and 'sex' fields are overwritten and Id is left as it is.
It's logical to think that the id is saved in session. you're right. I don't submit the id value, but spring can auto load its value into the id field.
All this is done automatically behind the scene. And that's what caused my confusion since the first place.
Anyway, all of this are assumption made by you and me. It may not be true from the documentation.
精彩评论