Click
  1. Click
  2. CLK-474

Format.message for MessageFormat.format

    Details

    • Type: Improvement Improvement
    • Status: Resolved
    • Priority: Minor Minor
    • Resolution: Fixed
    • Affects Version/s: 1.5
    • Fix Version/s: 2.0.1, 1.5.1
    • Component/s: core
    • Labels:
      None

      Description

      Could you please add this to net.sf.click.util.Format?

      public String message(String pattern, Object arguments)

      { return MessageFormat.format(pattern, arguments); }
      public String message(String pattern, Object[] arguments) { return MessageFormat.format(pattern, arguments); }

      Usually I extends Format as MyFormat and add this.
      I use this for $

      {format.message($pattern, $args)}

      in Velocity.

        Activity

        Hide
        Bob Schellink added a comment -

        Looks good. I'd suggest the implementation to cater for the Context Locale e.g.

        public String message(String pattern, Object[] arguments)

        { MessageFormat format = new MessageFormat(pattern, getLocale()); return format.format(arguments, new StringBuffer(), null).toString(); }

        regards

        bob

        Show
        Bob Schellink added a comment - Looks good. I'd suggest the implementation to cater for the Context Locale e.g. public String message(String pattern, Object[] arguments) { MessageFormat format = new MessageFormat(pattern, getLocale()); return format.format(arguments, new StringBuffer(), null).toString(); } regards bob
        Hide
        Bob Schellink added a comment -

        Do you have an example of how you use the second method taking an array?

        Was wondering because Velocity does constructs Lists, not arrays. For example:

        #set( $args = ["Superior","Michigan","Huron","Erie","Ontario"] )
        $format.message("

        {0}

        ", $args)

        will in fact invoke the first method because $args is a List not an array.

        In your use case do you pass in the array from Java?

        Otherwise we should have a message which takes a List.

        Show
        Bob Schellink added a comment - Do you have an example of how you use the second method taking an array? Was wondering because Velocity does constructs Lists, not arrays. For example: #set( $args = ["Superior","Michigan","Huron","Erie","Ontario"] ) $format.message(" {0} ", $args) will in fact invoke the first method because $args is a List not an array. In your use case do you pass in the array from Java? Otherwise we should have a message which takes a List.
        Hide
        Yu Kobayashi added a comment -

        I'm sorry. It's my mistake.

        public String message(String pattern, List<Object> arguments)

        { return MessageFormat.format(pattern, arguments.toArray(new Object[arguments.size()])); }

        is better.

        Show
        Yu Kobayashi added a comment - I'm sorry. It's my mistake. public String message(String pattern, List<Object> arguments) { return MessageFormat.format(pattern, arguments.toArray(new Object[arguments.size()])); } is better.
        Hide
        Bob Schellink added a comment -

        Fixed. Will be available for 1.5.1 and 2.0.1

        Show
        Bob Schellink added a comment - Fixed. Will be available for 1.5.1 and 2.0.1

          People

          • Assignee:
            Bob Schellink
            Reporter:
            Yu Kobayashi
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development