Iterate over a Resource Bundle

194 views
Skip to first unread message

Mike Trinh

unread,
Jul 6, 2015, 9:38:00 AM7/6/15
to hippo-c...@googlegroups.com
Hello,

So i just made a Resource Bundle and i was wondering if it was possible to iterate over a RBD to get all te possible keys. I am able to retrieve the data by using

<fmt:message key="event" bundle="${type}" />

With a forEach i want to iterate over the bundle and get the different keys.

Greets,

Mike Trinh

Jasper Floor

unread,
Jul 6, 2015, 10:05:40 AM7/6/15
to hippo-c...@googlegroups.com
Hi,

So not really a Hippo question but I'll give it a go.

With fmt setbundle you can put the bundle in a var and then you can call getKeys() (or maybe keySet()) and iterate over that set. Haven't ever tried this but it should work.

mvg,
Jasper
 

Mike Trinh

unread,
Jul 9, 2015, 7:26:10 AM7/9/15
to hippo-c...@googlegroups.com
Hey Jasper,

Sorry for my late reply. Is it possible to do this is the jsp file?

Op maandag 6 juli 2015 16:05:40 UTC+2 schreef Jasper Floor:

Jasper Floor

unread,
Jul 9, 2015, 8:41:57 AM7/9/15
to hippo-c...@googlegroups.com
On Thu, Jul 9, 2015 at 1:26 PM, Mike Trinh <mike....@incentro.com> wrote:
Hey Jasper,

Sorry for my late reply. Is it possible to do this is the jsp file?

Yes indeed.

<fmt:setBundle basename="some.bundle.name" var="someBundle"/>

<c:forEach items="${someBundle.keySet}" var="keys">
   ...
</c:forEach>


Something like that. Use keySet as it gives a Collection (Set) and getKeys gives an Enum which I don't think forEach can handle (but I'm not sure about that).

mvg,
Jasper

 
--
Hippo Community Group: The place for all discussions and announcements about Hippo CMS (and HST, repository etc. etc.)
 
To post to this group, send email to hippo-c...@googlegroups.com
RSS: https://groups.google.com/group/hippo-community/feed/rss_v2_0_msgs.xml?num=50
---
You received this message because you are subscribed to the Google Groups "Hippo Community" group.
To unsubscribe from this group and stop receiving emails from it, send an email to hippo-communi...@googlegroups.com.
Visit this group at http://groups.google.com/group/hippo-community.
For more options, visit https://groups.google.com/d/optout.

Mike Trinh

unread,
Jul 9, 2015, 9:16:31 AM7/9/15
to hippo-c...@googlegroups.com
Hey Jasper,

I added the code to my jsp but im getting a stacktrace. I have tried both the keySet and getKeys

Op donderdag 9 juli 2015 14:41:57 UTC+2 schreef Jasper Floor:

Jasper Floor

unread,
Jul 9, 2015, 9:39:29 AM7/9/15
to hippo-c...@googlegroups.com
hmm...I think maybe you can't iterate over the Set then...you might have to convert this to a List. I wouldn't do that on the Jsp. You should either write your own tag or do this in the backing component class.

Come to think of it, iterating over a set is a bit strange as it doesn't have an order. If you care about order.

mvg,
Jasper

Woonsan Ko

unread,
Jul 9, 2015, 10:59:03 AM7/9/15
to hippo-c...@googlegroups.com
According to [1], you cannot iterate with ResourceBundle#getKeys() like
other normal Java objects any more since JSP2.1.
You may still use the scriptlet code instead of JSTL tags.

[1] https://community.oracle.com/thread/1398785?start=0&tstart=0

On 7/9/15 9:39 AM, Jasper Floor wrote:
> hmm...I think maybe you can't iterate over the Set then...you might have
> to convert this to a List. I wouldn't do that on the Jsp. You should
> either write your own tag or do this in the backing component class.
>
> Come to think of it, iterating over a set is a bit strange as it doesn't
> have an order. If you care about order.
>
> mvg,
> Jasper
>
> On Thu, Jul 9, 2015 at 3:16 PM, Mike Trinh <mike....@incentro.com
> <mailto:mike....@incentro.com>> wrote:
>
> Hey Jasper,
>
> I added the code to my jsp but im getting a stacktrace. I have tried
> both the keySet and getKeys
>
> Op donderdag 9 juli 2015 14:41:57 UTC+2 schreef Jasper Floor:
>
>
>
> On Thu, Jul 9, 2015 at 1:26 PM, Mike Trinh
> <mike....@incentro.com> wrote:
>
> Hey Jasper,
>
> Sorry for my late reply. Is it possible to do this is the
> jsp file?
>
>
> Yes indeed.
>
> <fmt:setBundle basename="some.bundle.name
> <http://some.bundle.name>" var="someBundle"/>
> <mailto:hippo-c...@googlegroups.com>
> RSS:
> https://groups.google.com/group/hippo-community/feed/rss_v2_0_msgs.xml?num=50
> ---
> You received this message because you are subscribed to the Google
> Groups "Hippo Community" group.
> To unsubscribe from this group and stop receiving emails from it,
> send an email to hippo-communi...@googlegroups.com
> <mailto:hippo-communi...@googlegroups.com>.
> Visit this group at http://groups.google.com/group/hippo-community.
> For more options, visit https://groups.google.com/d/optout.
>
>
> --
> Hippo Community Group: The place for all discussions and announcements
> about Hippo CMS (and HST, repository etc. etc.)
>
> To post to this group, send email to hippo-c...@googlegroups.com
> RSS:
> https://groups.google.com/group/hippo-community/feed/rss_v2_0_msgs.xml?num=50
> ---
> You received this message because you are subscribed to the Google
> Groups "Hippo Community" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to hippo-communi...@googlegroups.com
> <mailto:hippo-communi...@googlegroups.com>.
> Visit this group at http://groups.google.com/group/hippo-community.
> For more options, visit https://groups.google.com/d/optout.


--
w....@onehippo.com www.onehippo.com
Boston - 745 Atlantic Ave, 8th Floor, Boston MA 02111
Amsterdam - Oosteinde 11, 1017 WT Amsterdam
US +1 877 414 4776 (toll free)
Europe +31(0)20 522 4466
Reply all
Reply to author
Forward
0 new messages