I hope someone can shed some light on this. I'm very new to jsp/servlets/jstl/struts,
java web development in general.
In one of my
Struts Action classes, I was placing a java.util.Map into the request scope.
In the
JSP doing the rendering for the action, I wanted to use the keySet of the map. Because .keySet() isn't actually a getter, I decided to make an inner wrapper class with the method .getKeySet(). I also wanted to be able use this same wrapper object as a normal Map. So I implemented the Map interface, delegated all the Map methods to my internal map, and created my .getKeySet() method which simply returned the keySet from the internal Map.
Pseudo-code (this was an inner class of the Action):
I had JSTL code in the JSP that looked like this:
It didn't work. I didn't error either, but it produced no output at all.
So I started debugging. Here's what I started with:
The first two lines in the last bit of code printed out:
com.my.package.some.CustomServlet$MapWrapper@3dc3943f
3
Which made sense. It got the classname in the toString, and the count was correct.
Strangely, the 3rd and 4th lines printed out nothing at and 0, respectively.
I thought this was odd and continued to attempt to debug for several hours. Eventually I commented out the Map interface on my MapWrapper class, and suddenly all of the debug lines started working!
So it appeared that JSTL couldn't access my custom methods if my wrapper class was implementing the Map interface.
I have since "solved" my problem and have basically worked around it, but I am really curious to understand why this behaved the way it did. Seems like this would really help further my understanding of JSTL because this would seem to be an odd problem. I didn't find anything on this site or Google.
Anyone have any insight?
Thanks!