2 Replies Latest reply: Mar 14, 2011 4:21 PM by 847316 RSS

    Problems with MessageFormat + ChoiceFormat

    843810
      All,

      First, this isn't strictly an i18n question, but it deals with various Format implementations which I understand are commonly used in this arena, thus my question is posted here.

      I have an application that uses MessageFormat as a template to an XML-encapsulated request. Recently we've been asked to choose between a couple of authentication options depending on the existance of a valid session token. I tried to use the ChoiceFormat pattern to achieve this, but I keep getting "Choice Pattern incorrect" errors. I seem to be mirroring the (somewhat ambiguous) documentation, but I could really use a hint from someone experienced in this.

      Here's the "choice" segment of the format I am using:
      {5,choice,0#<Username>foo</Username><Password>bar</Password>|1#<SessionID>baz</SessionID>}
      The parameters are {5} == 0 or 1 (Integer). At some point in the future, "foo" "bar" and "baz" are to be replaced with {3} {4} and {6} respectively (don't ask), to be the real username, password and (optional) session token.

      Can anyone tell me why, when this line is in my template, I get "Choice pattern incorrect" exceptions?

      Thanks!
        • 1. Re: Problems with MessageFormat + ChoiceFormat
          843810
          This is either a bug, or a escaping issue; take your pick. It turns out that the '<' character is interpreted as a special character, even when it's part of the body of the message. This can be thwarted by quoting the string using single quotes, but because of the location of the character, it would be relatively easy to determine that it is, in fact, not used specially.

          Thanks to anyone who read and considered my post.
          • 2. Re: Problems with MessageFormat + ChoiceFormat
            847316
            SunForumsGuest wrote:

            All,



            First, this isn't strictly an i18n question, but it deals with various Format implementations which I understand are commonly used in this arena, thus my question is posted here.



            I have an application that uses MessageFormat as a template to an XML-encapsulated request. Recently we've been asked to choose between a couple of authentication options depending on the existance of a valid session token. I tried to use the ChoiceFormat pattern to achieve this, but I keep <font face="tahoma,verdana,sans-serif" size="1" color="#000">getting</font> "Choice Pattern incorrect" errors. I seem to be mirroring the (somewhat ambiguous) documentation, but I could really use a hint from someone experienced in this.



            Here's the "choice" segment of the format I am using:







            The parameters are {5} == 0 or 1 (Integer). At some point in the future, "foo" "bar" and "baz" are to be replaced with {3} {4} and {6} respectively (don't ask), to be the real username, password and (optional) session token.



            Can anyone tell me why, when this line is in my template, I get "Choice pattern incorrect" exceptions?



            Thanks!
            Could you pls give more explanation on your needs? It is better for the answer.