Message Bundles
NUI could load messages from resource bundles and translate its parameters use OGNL Context.
Enhanced Message Format
NUI support enhanced message formatting(compare with WebWork). A message could include varius
parameter like this:
${parameterName[,data type[, format string]]}
The major different with WebWork message is support data type format.
For example, you can render a date value in specified format:
System time is: ${systemDate, date, dd/MM/yyyy hh:mm:ss}.
And choice format is also supported, it bring more powerful ability to developer.
NUI support format data type "js" , apply this format, content is encoded into a valid
JavaScript String value(not quoted). It's used in validator script templates.
Template n:out use same format to render its text.
Message format also can be used in element attribute value, but the message must start with a parameter(${..}).
Message Bundles Search Order
Message bundles are searched in the following order:
- /package-path/class-name.properties
- /package-path/class-name/property-name.properties
- /qualified-class-name.property-name.properties
- Search base class, e.g. /java/lang/Object.properties
- Search interfaces(and its sub-interfaces)
The path - file name combination is the prefix of message key. For example,
a message defined in bundle file /some/package/someclass.properties should use
"some.package.someclass." as it's prefix. Suppose the message name is "priority.title",
its key should be "some.package.someclass.priority.title".
NUI load bundle files by java.util.Properties instead of java.util.ResourceBundle, so only .properties file can be
found by NUI. It's an I8LN problem.
Rules of Message Key
NUI address a message by a unique key. By default, NUI use following rules to build a message key to load corresponding message.
Property Related Message Key
When render title or error message of property, NUI build a message key qualified-class-name.property-name.title and qualified-class-name.property-name.error
to address message.
For example, create a bundle file "Mail.properties" in /samples, and add a message for priority.title:
priority.title=${propertyValue == 1 ? '<b>' : ''}Mail Priority${propertyValue == 1 ? '</b>' : ''}
This message render title in bold style when priority is High(1). So change priority default value to 1 in Mail.java:
// default value is High priority.
private int priority = 1 ;
Here is result UI:

Validator Message Key
Validator use message to bulid error message.
The key of message is "nui.validator.validator-name".
NUI default validator message bundle is nui.validator.properties. Here is the content:
# nui validator resource bundle
required=${propertyTitle} is required.
int=${propertyTitle} is not a valid integer.
mail=${propertyTitle} is not a vaild E-Mail address.
date=${propertyTitle} is not valid date.
same=${propertyTitle} should same with ${withTitle}.
Native Encoding support
NUI can load resource bundle file (.properties) using special native encoding.
So you can write properties file in native char and forget native2ascii.
Following code set Simplified Chinese as default encoding:
TextProvider.setEncoding ("GBK") ;
Next