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[]
);
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
- is broken by
-
WICKET-3266 introduce varargs for parameters in StringResourceModel
- Resolved
- is related to
-
WICKET-4315 StringResourceModel skip first parameter in va args parameters, in case if first parameter has string type
- Closed
- relates to
-
WICKET-5702 Placeholders not substituted with StringResourceModel
- Closed