wicketwicket-7

How to display a simple wicket message with one simple parameter with StringResourceModel


I have one Wicket text property in the WicketApplicationProperties.properies

 <entry key="dataMniejszaNizMinimalna">Wybrano datę, która jest mniejsza niż minimalna akceptowalna data '${minimalnaData}'. Nie można zapisać danych."</entry>

How to substitute a parameter {minimalnaData} with a use of a class StringResourceModel. I don't want to create any models i want to just display a message with provided one attribute. The Wicket StringResourceModel is so complicated.

new StringResourceModel(resourceKey).setParameters(params)

how to provide this one parameter is a simplest way.


Solution

  • The simplest way could be:

    new StringResourceModel(resourceKey, this, Model.ofMap(Map.of("minimalnaData", "some value")))
    

    The model object could be a Java Bean or a java.util.Map.

    StringResourceModel also supports java.text.MessageFormat. You can use its #setParameters() method to pass an array of values for the placeholders.