The problem is the value of a key is a Class Object so I'm unsure what the syntax would be. Usually I can view the content in our of my classes like this:
Any suggestions? If you have any good documentation that you can point me to that would be great also.
Maybe I'm missing a step.
So I have a class object called Resource that contains the attributes(name, parent, owner, size, contenttype). I pass the HashMap() in which the key is the name of the file and the value is the Resource object of that file. I'm still confused as to how using jstl knows about the Resource object. Normally I would assign the value of
to an object like this: . I would then simply use but I can't do that in jstl (at least I don't think). I guess I'm confused as to how do I tie this all together. I haven't found many example like this when searching.
But if a Map implementation (it's a map, not a "hash") is established as a scoped variable, its values can be accessed simply by referring to its keys in the same way that you'd refer to bean properties.
So let's say that the Map is established as a scoped variable named myMap, and it had an entry with a key of someKey. It would be referenced simply as:
or, if the key is a non-identify such as some key:
or, if the key is the value of another scoped variable named xyz:
I have a class Object called Resource:
I have my method called getContents() that is called from my controller along with listFiles() which calls another method called collectAttributes()
Here is my Controller:
My controller is passing my contents HashMap(String, Resource Object) to my jsp page.
So, I guess my question is how do I access the Resource getName() method or better yet retrieve my Resource object attributes(name, parent, owner, size,contenttype) using jstl. Is this possible, or am I needing to configure my contents hashmap better to allow me to access this information?
laura mccord wrote:Well, I guess I don't know how to tell it that it's a Resource type since normally I cast the value of the key to be of type Resource. I don't know Spring well enough to get around this. Though I've read that I shouldn't have to cast the value as an object in EL.
There's no casting -- nor is there a need for it.
This message is telling you that the instance is a String. Not a Resource masquerading as a String, or anything else like that.
If you expected the Map entry's valye to be a Resource, then you've got a problem somewhere in your code where it's being set to a String rather than a Resource.
You cannot cast an instance of an object to something that it is not. Find out why your Map is badly formed.
should be the name of the resource in the body of the iterator.
Bear in mind that when iterating over a Map, you get the Map.Entry instances -- hence you need the key and value de-references.
When you directly access Map values, you get the value, not a Map.Entry. Hence no need for key and value.