Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

JSTL listing all keys of a property file  RSS feed

 
Zac Styris
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Guys

My requirement is to load a property file in to a JSP and then iterate the keys used in that property file. I used

<fmt:setBundle basename="bundles.loadbundle" var="bundles" scope="session"/>

to load the property file but i'm not allowed to iterate the keys using the following code

<c:forEach items="${bundles}" var="entry">
<cut value="${entry.key}"></cut>
<cut value="${entry.value}"></cut>
</c:forEach>

if would be great if anyone of you could help me on how to list all keys used in the property file and to iterate them.

Thanks
 
Andy Lileston
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've kinda got the same issue. I have my props in application scope and I'm trying to write a tag to get a certain property from the java.util.Properties.

JSTL is a bit new to me. I guess I could use a scriptlet but I wouldn't know how to transpose the incoming "key" variable into the scriptlet.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65826
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If the scoped variable is an instance of java.util.Properties, then it implements java.util.Map and you can iterate over it, or reference its entries, just like any other Map instance.
[ December 01, 2008: Message edited by: Bear Bibeault ]
 
Andy Lileston
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey Bear.

So would there be any other methodology in which I could get a particular property rather than having to iterate over them until I find the requested one? Using JSTL of course.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65826
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Map entries can be addressed in the same manner as bean properties using the EL.

For example:
or
In fact, you can almost think of Maps as "beans with dynamic property names" with respect to the EL.
[ December 01, 2008: Message edited by: Bear Bibeault ]
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!