I need help convincing Spring to bind to a map which has non-String keys. It may not be possible, in which case, some suggestions as to best implement a work-around would be helpful.
This is the type to which I'm trying to Map:
The relevant JSP looks like this:Code:public class Preferences { // <getters/setters omitted for brevity> private Map<LookupTableEntry, MyMapEntry> entries; } public class LookupTableEntry { // <getters/setters omitted for brevity> private int id; private String name; } public class MyMapEntry { // <getters/setters omitted for brevity> private String code; private BigDouble cost; }
Thsi fails because it's not clear how to bind from a String to a LookupTableEntry. The exact error is: Invalid property 'entries[LookupTableEntry@1f2412a]' of bean class [Preferences]: Value of nested property 'entries[LookupTableEntry@1f2412a]' is nullCode:<c:forEach items="${prefs.entries}" var="entry"> <tr> <td> ${entry.key.name} </td> <td> <spring:bind path="prefs.entries[${entry.key}].code"> <input type="text" name="${status.expression}" value="${status.value}"/> </spring:bind> </td> <td> <spring:bind path="prefs.entries[${entry.key}].cost"> <input type="text" name="${status.expression}" value="${status.value}"/> </spring:bind> </td> </tr> </c:forEach>
If I change the type for entries to Map<String, MyMapEntry>, everything works as expected. The problem is that I cannot embed the names of the keys in the map because they may change, which is why I'm using a lookup table. And I'm loading my lookup table using Hibernate, which is why I have a class representing an entry in the table.
I'm trying to find a clean solution, and this really seems like something that should have a straightforward solution. I'm just not seeing it!Maybe there's another approach that doesn't require non-String keys?
I found this trolling through JIRA, though I don't think it's something that will help me out. http://opensource.atlassian.com/proj...browse/SPR-392
Thanks!
Christian


Maybe there's another approach that doesn't require non-String keys?
Reply With Quote