-
Notifications
You must be signed in to change notification settings - Fork 10
Internationalization with StringResourceModel and ResourceModelFactory
In this page we are going to see how to internationalize Strings with StringResourceModel, ResourceBundleKey and ResourceModelFactory in Apache Wicket. The benefit of using this class is when migrating from wicket version 6* to version 7*.
The factory class ResourceModelFactory provides several factory methods that creates IModel object that can be further used for Internationalization of string objects.
Here is a simple example:
import de.alpharogroup.resourcebundle.locale.ResourceBundleKey;
import de.alpharogroup.wicket.base.util.resource.ResourceModelFactory;
...
IModel<String> descriptionResourceModel = ResourceModelFactory
.newResourceModel(ResourceBundleKey.builder()
.key("page.meta.description")
.defaultValue("A default description").build(),
this);
add(new Label("description", descriptionResourceModel));
The class ResourceBundleKey is pojo class that holds data for a properties key that can exist in a properties file. The class ResourceBundleKey can takes as mandatory the properties key and as optional values a default value and parameters.
In the above example it takes the key and a default value. If there is no value for the key the default value will be taken and no missing exception will be thrown.