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

OptionWriter renders item Maps incorrectly (no preselection) [SPR-4385] #9064

Closed
spring-projects-issues opened this issue Jan 24, 2008 · 4 comments
Assignees
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) status: backported An issue that has been backported to maintenance branches type: bug A general bug
Milestone

Comments

@spring-projects-issues
Copy link
Collaborator

spring-projects-issues commented Jan 24, 2008

Benjamin Hoffmann opened SPR-4385 and commented

When rendering an Option, renderFromMap() passes the HashMap Entry to the renderOption Method instead of the keyObject itself.

private void renderFromMap(final TagWriter tagWriter) throws JspException {
     final Map optionMap = (Map) this.optionSource;
     for (Iterator iterator = optionMap.entrySet().iterator(); iterator.hasNext();) {
          Map.Entry entry = (Map.Entry) iterator.next();
          Object mapKey = entry.getKey();
          Object mapValue = entry.getValue();
          BeanWrapper mapKeyWrapper = new BeanWrapperImpl(mapKey);
          BeanWrapper mapValueWrapper = new BeanWrapperImpl(mapValue);
          Object renderValue = (this.valueProperty != null ? mapKeyWrapper.getPropertyValue(this.valueProperty)
                        : mapKey.toString());
          Object renderLabel = (this.labelProperty != null ? mapValueWrapper.getPropertyValue(this.labelProperty)
                        : mapValue.toString());
          renderOption(tagWriter, entry, renderValue, renderLabel);
     }
}

The renderOption Method compares the item as well as the textual representation to determine the selection state of the specific option. The MapEntry will never match in this case, so the mapEntry.getKey() should be passed to renderOption instead.


Affects: 2.0.8, 2.5.1

Issue Links:

Backported to: 2.0.9

@spring-projects-issues
Copy link
Collaborator Author

Juergen Hoeller commented

Good point, this should be the raw Map key in this case, so that a match with the raw key qualifies for the selection check as well.

This will be available in tonight's 2.5.2 snapshot (-382 or above; available from http://static.springframework.org/downloads/nightly/snapshot-download.php?project=SPR). Please give it a try and let us know whether it works for you...

Juergen

@spring-projects-issues
Copy link
Collaborator Author

Benjamin Hoffmann commented

Hi Juergen,

worked well for me, but there seems to be an analogous Problem with the Checkbox Tag. I didn't debug it yet, but it shows the same behaviour when using a Map as items Object...

Benjamin

@spring-projects-issues
Copy link
Collaborator Author

Juergen Hoeller commented

Thanks for the feedback!

There could indeed be a similar in checkbox rendering. It would be great if you could debug this a bit more closely, since it's not immediately obvious where the check could be missing there... The code does seem to check against the raw Map key already.

Juergen

@spring-projects-issues
Copy link
Collaborator Author

Benjamin Hoffmann commented

I'll give it a try and open a new issue if i figure something out.

thanks for the fast response anyway!

Benjamin

@spring-projects-issues spring-projects-issues added type: bug A general bug status: backported An issue that has been backported to maintenance branches in: web Issues in web modules (web, webmvc, webflux, websocket) labels Jan 11, 2019
@spring-projects-issues spring-projects-issues added this to the 2.5.2 milestone Jan 11, 2019
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: backported An issue that has been backported to maintenance branches type: bug A general bug
Projects
None yet
Development

No branches or pull requests

2 participants