Re: Table-ize error messages

2019-11-14 Thread János Cserép

Easiest way to do it is to create a custom resource loader like this:

public class DatabaseResourceLoader implements IStringResourceLoader {

(...)

    @Override
    public String loadStringResource(Class clazz, String key, Locale 
locale, String style, String variation) {
    return messageService.getStringResource(key, 
locale.getLanguage());

    }

    @Override
    public String loadStringResource(Component component, String key, 
Locale locale, String style, String variation) {
    return messageService().getStringResource(key, 
locale.getLanguage());

    }
}

In your application init class you need to add the resource loader:

   getResourceSettings().getStringResourceLoaders().add(new 
DatabaseResourceLoader()); // db lookups performed only if key is 
missing from properties files


or

   getResourceSettings().getStringResourceLoaders().add(0, new 
DatabaseResourceLoader()); // db lookups are first, you can override 
translations from properties in the db



Note: you don't need to worry about caching, wicket will cache results 
from resourceloaders. If they change in the db, you can call  
Application.get().getLocalizer().clearCache() to invalidate it.



On 2019. 11. 14. 21:43, Entropy wrote:

Most of our error messages are in property files, but we have a set of them
that we need to draw from a database.  I'd like to add them to the resources
programmatically in the Application object at startup so that pages don't
know any difference between whether it was sourced from property files or
the database.

How can I add them to whatever pool the app is pulling from when I do
getString(name)?

--
Sent from: http://apache-wicket.1842946.n4.nabble.com/Users-forum-f1842947.html

-
To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org



-
To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org



Table-ize error messages

2019-11-14 Thread Entropy
Most of our error messages are in property files, but we have a set of them
that we need to draw from a database.  I'd like to add them to the resources
programmatically in the Application object at startup so that pages don't
know any difference between whether it was sourced from property files or
the database.

How can I add them to whatever pool the app is pulling from when I do
getString(name)?

--
Sent from: http://apache-wicket.1842946.n4.nabble.com/Users-forum-f1842947.html

-
To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org