Reputation: 435
I am using Tapestry and want to pass a various number of parameters to .properties file to print out messages on screen.
For example, I want to print the message out like this:
How would I define messages in properties file so that a various number of parameters can be passed? Can I pass them in list?
message=The messages for {0} - {1, list}
Upvotes: 1
Views: 896
Reputation: 328
Tapestry provides a org.apache.tapestry.ioc.Messages
service (in tapestry-ioc) which you can inject in any component to:
.properties
file attached to this component (method String get(String key)
),MessageFormatter
object to do a kind of "String.format(...)" of a property of this same file.On Java side, in a component class, what you can do to build a message the way you want is:
public class MyComponent {
@Inject
private Messages messages;
@Property
private String messageToDisplay;
@SetupRender
final void init() {
// ...
messageToDisplay = messages.get("some-key").format(valueForParam0, valueForParam1, ...);
// ...
}
}
Moreover, up from v5.3 of Tapestry, you can use the org.apache.tapestry5.alerts.AlertManager
service to easily display messages as alerts (with level like "info", "warn", etc.).
Upvotes: 1