1 Reply Latest reply on Jun 24, 2009 3:35 PM by Nikos Paraskevopoulos

    Dynamic Label using properties file

    Tekchand Prasad Newbie
      <s:selectItems value="#{address.state.values()}" var="sp"
                                                      label="#{messages['person.state.'#{sp}]}"
                                                              itemValue="#{sp}" >                                                                                                  </s:selectItems>
      <s:convertEnum />
      </h:selectOneMenu>



      I want to display label using properties file.
      messages en.properties file contain
      person.state.AL
      person.state.MA


      and address.state.values return


      AL
      MA


      Thanks
      Tekchand

        • 1. Re: Dynamic Label using properties file
          Nikos Paraskevopoulos Novice

          EL does not support String concatenation, so I create a Facelets library with an EL function for string concatenation and use it like:


          <ui:composition ... xmlns:xx="http://www.my-own-url.com/jsf/facelets">
            <s:selectItems ... label="#{messages[xx:strcat('person.state.',sp)]}" .../>
          </ui:composition>
          



          To do this you need a file called eg xx.taglib.xml like:


          <?xml version="1.0"?>
          <!DOCTYPE facelet-taglib PUBLIC
               "-//Sun Microsystems, Inc.//DTD Facelet Taglib 1.0//EN"
               "https://facelets.dev.java.net/source/browse/*checkout*/facelets/src/etc/facelet-taglib_1_0.dtd"
          >
          <facelet-taglib>
               <namespace>http://www.my-own-url.com/jsf/facelets</namespace>
               <function>
                    <function-name>strcat</function-name>
                    <function-class>xx.Util</function-class>
                    <function-signature>java.lang.String strcat(java.lang.String,java.lang.String)</function-signature>
               </function>
          </facelet-taglib>
          



          Then the class xx.Util:


          public class Util
          {
               public static String strcat(String s1, String s2) {
                    return s1+s2;
               }
          }
          



          And finally declare the Facelets library in web.xml:


               <context-param>
                    <param-name>facelets.LIBRARIES</param-name>
                    <param-value>/WEB-INF/xx.taglib.xml</param-value>
               </context-param>