4 Replies Latest reply on Aug 18, 2009 4:44 PM by Alex Cougarman

    Can't read properties file on Seam page

    Alex Cougarman Apprentice

      I'm trying to read the file RequestForms.properties located in the WEB-INF/classes folder. What am I doing wrong? The file contains the following entry:


      person.name=Jane Smith



      The file is loaded using this:


      <f:loadBundle basename="RequestForms" var="forms" />



      Then I try reading the person.name property like this:


      <h:outputText value="#{forms.person.name}" />



      I get the following error:


      javax.el.PropertyNotFoundException: /employee-exit/employee_exit.xhtml @14,52 value="#{forms.person.name}": Property 'name' not found on type java.lang.String

        • 1. Re: Can't read properties file on Seam page
          Jaime Martin Apprentice
          I think the problem is the dot.
          Replace person.name with person_name, so it would be:

          `person_name=Jane Smith`


          and then:

          `<h:outputText value="#{forms.person_name}" />`

          If you want to keep on using the dot maybe the syntax used for
          messages bundle would work, so in that case try this:

          '
          #{forms['person.name']}
          '
          • 2. Re: Can't read properties file on Seam page
            Alex Cougarman Apprentice

            Thanks, Jaime. The last example you gave works. But I'm curious, why does the second dot confuse it? I've searched on this error and couldn't find an explanation as to why it gives that particular java.lang.String exception. Thank you :)

            • 3. Re: Can't read properties file on Seam page
              Jaime Martin Apprentice

              It´s due to a limitation of the EL with bundle processing.
              If you only use a dot, it considers what is after the dot to be the name of the property, and it would return a String with the value of that property. In your case this String is Jane Smith.
              On the other hand, if you use 2 dots it considers what is after the second dot to be a property of the previous object, so it is trying to find a name property in Jane Smith, which is a String. That´s why the error message displayed although weird is correct.
              To avoid this EL wrong behaviour with dots you have to use the syntax I said before.


              #{forms['person.name']}
              


              This way person.name is considered as a unit for the EL and is passed as a parameter to search that unit inside the properties file. And that´s all!




              • 4. Re: Can't read properties file on Seam page
                Alex Cougarman Apprentice

                Thanks, Jaime. I thought I was losing my mind when trying to make the two dots work, but your explanation makes it all very clear :)
                Thank you again.