4 Replies Latest reply on Oct 31, 2007 12:53 PM by mars1412

    Seam Text: message format

    mars1412 Apprentice

      in the .properties file, I have a text that includes standard java message formatting - e.g.

      mtr.test.param.format=string {1} currency {0,number,#.##} integer {0,number,integer}.


      in the web-page i use the following code to generate the output:
       <h:outputFormat value="#{messages['mtr.test.param.format']}">
       <f:param value="3.145" />
       <f:param value="a disturbance in the Force" />
       </h:outputFormat>
      

      but the rendered string is:
      string a disturbance in the Force currency 3.145 integer 3.145.
      

      why does the #.## not work with h:outputFormat?

      is this my mistake, or does h:outputFormat not support all java message format identifiers?
      http://java.sun.com/javase/6/docs/api/java/text/MessageFormat.html

      thanks in advance

        • 1. Re: Seam Text: message format
          Pete Muir Master

          Ask on a JSF forum.

          • 2. Re: Seam Text: message format
            mars1412 Apprentice

            well, I asked it on a JSF forum - no reply
            however, I wrote a simple sample application with JSF on JBoss without SEAM and it worked as expected (but I used jsp instead of facelets)

            anyway

            I just debugged into the SEAM source and found out, that the problem is, that the messages component (org.jboss.seam.international.Messages) calls SeamResourceBundle.getString() which in turn calls Interpolator.interpolate() before returning the string

            so I wrote another simple SEAM example:

            String source = "{0,number,#.#}";
            String interpolated = Interpolator.instance().interpolate(source);
            System.out.println("soruce: '"+source+"'");
            System.out.println("interpolated: '"+interpolated+"'");
            


            which prints the following output on stdout:

            17:02:00,133 INFO [STDOUT] soruce: '{0,number,#.#}'
            17:02:00,133 INFO [STDOUT] interpolated: '{0}'


            next test was to create a simple java file, that does following:
            String expr = "{0,number,#.##}";
            String value = new MessageFormat(expr, java.util.Locale.getDefault()).format(null);
            System.out.println("expr : "+expr);
            System.out.println("value: "+value);
            

            which results in:

            expr : {0,number,#.##}
            value: {0}



            so now I know why it does not work, but I'm not sure what to do about it.

            • Is it a problem of the JRE?
              it seems strange to me that format() changes my string, although I do not pass any parameters..
            • Or should Seam's Interpolator.interpolate() not call
              MessageFormat.format() if there are no parameters?


            • 3. Re: Seam Text: message format
              Pete Muir Master

              Please file a jira issue, we'll need to look at this in detail.