Spring MVC 3 - Binding parameters to backing object?

I would suggest separating your front-end code from the logic for what will be saved in the database. The form backing object is just meant to be a simple object that captures want the user has done in the view... it shouldn't be used to save directly to the database. I would have a Service layer handle the decision on whether or not to update certain fields... the controller should just receive the input and pass it along.

This way, the service can decide what fields should be updated.

I would suggest separating your front-end code from the logic for what will be saved in the database. The form backing object is just meant to be a simple object that captures want the user has done in the view... it shouldn't be used to save directly to the database. I would have a Service layer handle the decision on whether or not to update certain fields... the controller should just receive the input and pass it along.

This way, the service can decide what fields should be updated. Public void updateUser(long userId, User updatedUser) { User currentUser = dao. GetCurrentUserById(userId); currentUser.

UserName = updatedUser. Username; //...... update anyother fields.... dao. SaveUser(currentUser); } or you could define the method in a way that the caller knows what will be updated: public void updateUser(long userId, String updatedUsername); I would also argue that this is a lot easier to unit test if this logic is in the Service Layer.

Hope this helps.

Add this to your controller: @InitBinder protected void initBinder(WebDataBinder binder) { binder. SetAllowedFields("field1", "field2"); }.

You simply don't use it as hidden field(how can a user guess about your field name). Alternatively you can just ignore it to update while doing the update.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions