PrzemyslawP
PrzemyslawP

Reputation: 340

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.

Upvotes: 0

Views: 711

Answers (2)

martin-g
martin-g

Reputation: 17533

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.

Upvotes: 2

Andrea Del Bene
Andrea Del Bene

Reputation: 2511

I think wicket:message should fit your need. Take a look at the wiki:

https://cwiki.apache.org/confluence/display/WICKET/Wicket%27s+XHTML+tags

You can nest components within textual content.

Upvotes: 1

Related Questions