java - Spring MVC, one controller for "add" and "update" when using setDisallowedFields? -


So I have a simple form through which I can "add" a new thing or an existing "update" thing .

What I would like to do is a controller who can process both adding and updating. In the beginning it seems quite simple, unless I consider the problem of using setDisallowedFields in my InitBinder so that the "id" field is not allowed during adding a new item.

Currently I have two controllers which can be the same code except for the Endbinder method.

Any suggestions or advice? (I'm open to the argument that I should also keep two controllers, if you can give me good reason)

Basically, you should reject both the" id "field when adding and updating. Otherwise the "id" of the malicious user update request may be compromised with the value of the request parameter and thus update any other records shown by the form (assuming no ACL or other domain-level security is assumed).

However, if you reject the "id" field, you see the controller ID blank, which will work when inserting, but will not be time to update (for example, instead of updating this, a new record You can try to put it, based on the firmness mechanism you are using). You want the administrator to remember the non-editable values ​​of your domain object (not only ID, but all denied fields) in order to send all correct values ​​for this service level or other business logic. This type-level @ session entry is done using annotation, as follows (other comments to be left for clarity):

  @ session attraction ("cheese") // Domain object name public class ThingController {Public Zero set Diselfeld (webdetabiner binder) {binder.setDisallowedFields ("id", "someOtherUneditableField"); } // ways to deal with requests, go here as before)  

For better security, set the allowed areas instead of the denied areas

< / Html> Whatever you need to do @ session entries annotation to fill the existing field values,

Comments

Popular posts from this blog

python - Overriding the save method in Django ModelForm -

html - CSS autoheight, but fit content to height of div -

qt - How to prevent QAudioInput from automatically boosting the master volume to 100%? -