Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Corrupt Data - data on second page of submit is corrupted when referenced via "path" attribute (but is fine when referenced using jstl) [SPR-10442] #15075

Closed
spring-projects-issues opened this issue Apr 4, 2013 · 2 comments
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) status: bulk-closed An outdated, unresolved issue that's closed in bulk as part of a cleaning process

Comments

@spring-projects-issues
Copy link
Collaborator

Will Dev opened SPR-10442 and commented

See attached pictured called "Spring MVC Bug - Screenshot" for the fastest explanation.

When -

  1. A form's modelAttribute value is the same as the class name (or starts with the classname - softwareVendorVO2 had the same problem)
  2. Data is referenced through the path variable on a form item
  3. indexes are used
  4. A page is submitted
  5. On the new page - despite the data being sent to the page being completely new - it's displaying totally different data.

You can see from the screenshot - the actual data, being referenced by jstl and ${}, is correct. But the data displayed via the path="" attribute is completely wrong and different data. (In the controller, the data on the 2nd page is not from the first page - it's completely newly created data).

This is causing problems where:

  1. The checkboxes on the second page are blank - even though they should be checked
  2. I'm having issues where string labels are having the same problem - the second page has the values from the first page, even though it should have a completely new set of values
  3. Sometimes I'm seeing corruption in the string data - a value like "bob" is showing up on the second page as "bob,bob" or "bob,bob,bob", etc.

Note that the attached files only show problem #1 - I just didn't have time to reproduce test cases for #2 and #3.

But all problems go away when the modelAttribute name is changed to something that's not the same as the class name.

But it's VERY COMMON, as far as I know (as that's what everyone on our team did by default) to use the classname as the model name. This just shouldn't be happening, something is getting corrupted or something somewhere.


Affects: 3.2.2

Attachments:

@spring-projects-issues
Copy link
Collaborator Author

Min Byung Seok commented

If @ModelAttribute("softwareVendorVO") is used in controller parameters, the object named "org.springframework.validation.BindingResult.softwareVendorVO" will be put into ModelMap after binding.

As using ModelAndView with the same model name,
->
new ModelAndView("edit_page", "softwareVendorVO", createTestData());

modelMap were supposed to overwrite the new data,
but Let see - HandlerMethodInvoker.updateModelAttributes().
->
if (mavModel != null && !model.containsKey(bindingResultKey)) {
WebDataBinder binder = createBinder(webRequest, attrValue, attrName);
initBinder(handler, attrName, binder, webRequest);
mavModel.put(bindingResultKey, binder.getBindingResult());
}

Before putting bindingResult data to the map, it will check if the same bindingResultKey is contained in model. In this case, the bindingResultKey name is "org.springframework.validation.BindingResult.softwareVendorVO".

Because the bindingResultKey is same with the parameter value( @ModelAttribute("softwareVendorVO") ), this inner logic will be skipped so that the data of submit is currupted.

If you edit this part to overwrite the model instead of checking bindingResultKey and skipping, it will be solved.

However I also wonder why this logic-> !model.containsKey(bindingResultKey)( checking if there's same key model.)
is necessary , and what kind of problem will be caused after editing "if conditional" to overwrite modelMap.

Can anyone tell me why overwriting modelMap is not permitted in spring?
How much scope will be effeced if modelMap is overwritted?

@spring-projects-issues spring-projects-issues added type: bug A general bug status: waiting-for-triage An issue we've not yet triaged or decided on in: web Issues in web modules (web, webmvc, webflux, websocket) and removed type: bug A general bug labels Jan 11, 2019
@rstoyanchev rstoyanchev added status: bulk-closed An outdated, unresolved issue that's closed in bulk as part of a cleaning process and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels Jan 11, 2019
@spring-projects-issues
Copy link
Collaborator Author

Bulk closing outdated, unresolved issues. Please, reopen if still relevant.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) status: bulk-closed An outdated, unresolved issue that's closed in bulk as part of a cleaning process
Projects
None yet
Development

No branches or pull requests

2 participants