8 Replies Latest reply on Jan 16, 2007 11:44 AM by Pete Muir

    resource-bundle question

    Yoav Al Newbie

      In Chapter 8 in the Seam - Contextual Components there is a topic about resource bundle in seam. I followed the examples and did not make it to work...

      I have a country.properties file, I?ve put it in WEB-INF/classes and add the following to the components.xml

       <component name="org.jboss.seam.core.resourceBundle">
       <property name="bundleNames">

      And then I tried to get it like so:

       <h:selectOneListbox >
       <f:selectItems value="#{countries}"/>

      But I got null exception for countries.
      Where did I go wrong?
      And how can I change the default location of the properties, I want to put it in WEB-INF/resources (instead of classes)


        • 1. Re: resource-bundle question
          Michael Singer Newbie


          <f:selectItems value="#{messages[some.key]}"/>

          where some.key is

          some.key = some strange text

          in your countries.properties

          • 2. Re: resource-bundle question
            Yoav Al Newbie

            but i want to go over all countries not only one

            • 3. Re: resource-bundle question
              Yoav Al Newbie

              and another question
              how can I get a message value dynamically?

              for instance:

              String msgValue = 'someValue';
              #{messages[ msgValue ] }

              is possible?

              • 4. Re: resource-bundle question
                Pete Muir Master

                You can't use a message bundle like that - it's for internationalisation of messages, not iteration. You'll need to use a Collection of some sort in a backing bean or specify them in the view descriptor itself (use f:selectItem).

                If, by your second question, you're asking how you get a message in a backing bean (seam component):

                private Map messages;
                public void foo() {
                 String message = (String) messages.get("foo");

                • 5. Re: resource-bundle question
                  Yoav Al Newbie

                  OK that work great,

                  i used a bundleLoader that loads the messages
                  but how can i print out useing <h:outputText>
                  a specific country

                  public void foo(String value) {
                  String message = (String) messages.get( value );

                  and for my first question, how can i load more resourses ?
                  is it enough to put the property file in the WEB-INF/classes ?

                  • 6. Re: resource-bundle question
                    Pete Muir Master

                    I'm not really following you here but, here goes

                    <h:outputText value="#{messages.china}" />

                    would work if you had a key called china in your message bundle (by default messages.properties).

                    I'm not sure what you mean by 'load more resources', but, if you mean to split your message bundles into multiple files, then yes, put the xxx.properties on the classpath and tell Seam about them in components.xml.

                    You probably don't want to use f:loadBundle (at least I assume thats what you mean by a 'bundleLoader') but use Seam's message bundle support instead.

                    • 7. Re: resource-bundle question
                      Yoav Al Newbie

                      when i wrote 'bundleLoader' i mean a bean that loads the resource bundle and i use resources throw the bean. that way i can sort and do all kind of mnipulation on the data before i show it.
                      i do not use f:loadBundle .

                      What i want to do is this:

                      <t:dataTable id="myTripsTable"
                       cellpadding="2" cellspacing="0" border="0"
                       rowOnMouseOut="this.bgColor='#FFFFFF';" >
                      <t:column style="width:30%;">
                       <s:link view="/TripDetails.jsp" value="#{aTrip.name}" action="#{tripManager.selectFromRequest}" propagation="end">
                       <f:param name="id" value="#{aTrip.id}"/>
                      <t:column style="width:20%;">
                       <h:outputText value="#{aTrip.startDate.time}">
                       <f:convertDateTime pattern="dd/MM/yyyy"/>
                      <t:column style="width:20%;">
                       <h:outputText value="#{aTrip.country}" />
                      <t:column style="width:5%;">
                       <a4j:commandLink action="#{tripsManager.selectTripForEdit}"
                       <h:graphicImage url="images/edit_icon.gif" alt="Edit Trip" style="border:0px;" />
                      <t:column style="width:5%;">
                       <a4j:commandLink action="#{tripsManager.deleteTrip}"
                       onclick="if (!window.confirm('Delete Trip ?')) return false;"
                       <h:graphicImage url="images/delete.gif" alt="Delete Trip" style="border:0px;" />

                      look at the: aTrip.country - the country that the aTrip holds is a key in the country resource, i want to display the value.
                      so i need to do something like this: #{country[ aTrip.country ]}
                      of course this will not work, so wht will ?

                      • 8. Re: resource-bundle question
                        Pete Muir Master

                        Assuming you are using the Seam message bundle #{messages[aTrip.country]} will retrieve a resource that has #{aTrip.country} as the key.