Uploaded image for project: 'Wicket'
  1. Wicket
  2. WICKET-4972

Remove (or disarm) varargs contructors of StringResourceModel (more of a pitfall than convenience)

    XMLWordPrintableJSON

    Details

    • Type: Wish
    • Status: Resolved
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 6.4.0
    • Fix Version/s: 7.0.0-M1
    • Component/s: wicket
    • Labels:
      None

      Description

      The introduction of varargs constructors for StringResourceModel also introduced a pitfall which (IMO) outweighs the convenience of not explicitely having to create an array.

      When using this constructor:

      public StringResourceModel(final String resourceKey, final Component component, final IModel<?> model, final Object... parameters)

      one runs into problems when parameters are of type String (which probably happens more often than not), since the VM acutally ends up calling

      public StringResourceModel(final String resourceKey, final Component component, final IModel<?> model, final String defaultValue, final Object... parameters)

      From my experience, this happens repeatedly to Wicket newbies, but still to "veterans" sometimes.

      Example (does not work as one would expect):
      new StringResourceModel("my.resource.key", this, getModel(), "first param to replace", "second param to replace");

      Forcing to do either
      new StringResourceModel("my.resource.key", this, getModel(), null, "first param to replace", "second param to replace");
      or
      new StringResourceModel("my.resource.key", this, getModel(), newObject[]

      {"first param to replace", "second param to replace"}

      );

      I think varargs is a convenient feature, but in this special case it introduces confusion, outweighing the convenience by far, thus I suggest to expect explicit array like before.
      Another solution might be to expect a Model<String> as defaultValue or to change the order of constructor arguments.

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                mgrigorov Martin Tzvetanov Grigorov
                Reporter:
                pparson Peter Parson
              • Votes:
                0 Vote for this issue
                Watchers:
                3 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: