7 Replies Latest reply on Sep 4, 2008 10:13 PM by tomek szzzaaos

    dynamic messages

    tomek szzzaaos Newbie

      Hi,


      Could anyone tell me if it's possible to do something like:



      <h:dataTable var="item" value="#{orderList.resultList}">
        <h:column>
          <h:outputText value="#{messages['#{item.status}']}" />
        </h:column>
      </h:dataTable>



      Thank you,


      Tomek

        • 1. Re: dynamic messages
          Vladimir Kovalyuk Apprentice

          The following should work:



          <h:dataTable var="item" value="#{orderList.resultList}">
            <h:column>
              <h:outputText value="#{messages[item.status]}" />
            </h:column>
          </h:dataTable>


          • 2. Re: dynamic messages
            tomek szzzaaos Newbie

            For me it renders nothing just empty column. Even if there is no entry in the messages*.properties file.

            • 3. Re: dynamic messages
              Jaime Martin Apprentice

              hi,
              what Vladimir said is the proper syntax. I use it in plenty of places of mu application and it works.
              Check if you have an entry for the value of item.status in your messages properties file.
              And remember that an entry called item.status in the properties file will not work.
              Try to display item.status value this way


                <h:column>
                  <h:outputText value="#{messages[item.status]}" />
                </h:column>
                <h:column>
                  #{item.status}
                </h:column>
              



              Check if both columns are empty. If the second is empty of course the first would be empty as well.In that case debug or check the database to find out why is that value empty. If empty.status has a value,  for instance btw you should have an entry in the properties. For example


              btw=By the way
              


              Hope this has helps you!



              • 4. Re: dynamic messages
                tomek szzzaaos Newbie

                It's done exactly as you both say.


                I think I know what is the problem, item.status is defined as enum, cos I tried with other types like String and it's fine.

                • 5. Re: dynamic messages
                  tomek szzzaaos Newbie

                  Does it work for anyone with enums? I think it would be quite useful if it does.


                  I got something like:



                  @Entity
                  public class Order{
                     public String code;
                     public Status status;
                  
                     public enum Status{
                        NEW_ORDER(1),
                        ALLOCATED(2);
                         
                        private intValue;
                  
                        private Status(int value){
                            this.intValue = value;
                        }
                     }
                  }



                  and then


                  <h:dataTable var="item" value="#{orderList.resultList}">
                    <h:column>
                      <h:outputText value="#{messages[item.status]}" />
                      <h:outputText value="#{item.status}" /> <!-- this works fine -->
                    </h:column>
                  </h:dataTable>



                  anyone? please :)

                  • 6. Re: dynamic messages
                    Vladimir Kovalyuk Apprentice

                    try item.status.name() and place properties NEW_ORDER and ALLOCATED into your messages.properties

                    • 7. Re: dynamic messages
                      tomek szzzaaos Newbie

                      Only the way I could get around the problem was adding the method getName() to enum. After that everything works fine.



                      Thanks guys for help!


                      Tomek