Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Version History

Version 1 Current »

TBD


The dollar function $()

Within a page the $() function translates a resource key and optional parameters to a string. The usage is something like this:

MsgBox(this, $("recordNotFound", getName()));

The $ function locates the message string from one of the message bundles for the class it is in, uses NlsContext.getLocale() to find the current language, then uses MessageFormat() to format that text using the other parameters of the $ function. This is the quickest way to use message bundles for components and pages.

The $ function uses message bundle inheritance to build a message bundle stack: an ordered set of message bundles. The stack is formed as follows:

  • Starting with the current class (as returned by getClass()), try to find a message bundle for this class as follows:
    • Use the class name in the class's package and add .properties. If this bundle is found add it to the bundle stack.
    • Use the class's package and look for a messages.properties. If that exists: add it to the stack
    • Move upward to the class package and check for messages.properties there; when found add them to the stack
  • Now move to the superclass of the current class and do the exact same again.

This mechanism leads to a stack of bundles with message bundles for both the actual class but also for all base classes of that class in that stack, with the current class the 1st bundle.

Now when the $() function looks up a key it walks the stack and uses the string from the first bundle it finds.

In effect this does the following:

  • Every class can have either a class message bundle (ClassName.properties) or a package level bundle (messages.properties) associated with it.
  • All of a class' parent classes also can have bundles, and together they form a "search path" for keys.
  • A new class X can both add its own keys to its own base class, but it can also override all of the keys that its parent classes use for texts by providing an alternate value in its class bundle!

Let's give an example.

We make a new page called CustomerListPage which extends AbstractListPage.

AbstractListPage has its own bundle (AbstractListPage*.properties), and there is a piece of code that states:

lf.getButtonFactory().addButton($("newButton"), Theme.BTN_NEW, a -> addNew());

This adds a button with the button text coming from the "newButton" value inside the AbstractListPage.properties bundle.

If I do not like the text on the button I can create a new message bundle CustomerListPage.properties and add the newButton=xxxxx inside there to override the text.





  • No labels