1

I am using a database to hold all text values of my web pages so i can switch between different languages. I added JSF 2.0 to my project but failed when i tried to get the validation messages from my database too. Is there a way to write my own validation-messagesource which retrieves the messages from a database?

I'd really appreciate any help!

Thank you all in advance,

best regards, Robert

Robert M.
  • 1,339
  • 1
  • 12
  • 34
  • Related: http://stackoverflow.com/questions/4499732/design-question-regarding-java-ee-entity-with-multiple-language-support/4500633#4500633 – BalusC Jan 07 '11 at 11:05

1 Answers1

0

You could extend java.util.ResourceBundle and put something like this in faces-config.xml:

<application>
    <locale-config>
        <default-locale>en</default-locale>
    </locale-config>
    <message-bundle>package.MyResourceBundle</message-bundle>
    <resource-bundle>
        <base-name>package.MyResourceBundle</base-name>
        <var>msg</var>
    </resource-bundle>
</application>
Bjørn Stenfeldt
  • 1,432
  • 1
  • 18
  • 25
  • I tried it this way, but this results in `java.util.MissingResourceException: Can't find bundle for base name at.luxbau.mis2.web.i18n.ResourceBundle, locale de` – raho Nov 09 '17 at 06:12
  • Using it with ` ValidationMessages` where `ValidationMessages_xx.properties` is in `src/main/resources` resulting with `WEB-INF/classes/ValidationMessages_xx.properties` in my WAR works as expected. – raho Nov 09 '17 at 06:13
  • I sometimes get that error too. I've fixed it simply by creating another empty class that does nothing but extending `package.MyResourceBundle` and then naming that other class `package.MyResourceBundle_de` or similar. – Bjørn Stenfeldt Nov 09 '17 at 09:20
  • I have already two classes which extend from `ResourceBundle` namely `at.luxbau.mis2.web.i18n.ResourceBundle_de` and `at.luxbau.mis2.web.i18n.ResourceBundle_en`. But using it with `at.luxbau.mis2.web.i18n.ResourceBundle` always results in `MissingResourceException` – raho Nov 10 '17 at 09:53
  • Can't tell what the problem might be with that without some source code to look at. – Bjørn Stenfeldt Nov 10 '17 at 10:04
  • Can I send you my code examples per mail or show them via remote session? If you are too busy, I use my workaround, by using a properties file for the validation translations. – raho Nov 13 '17 at 08:39