Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

  • Isomorphic
    replied
    condition() is invoked via DMI. After the first 5 required parameters, any of the optional parameters can be declared, including HttpServletRequest.

    Leave a comment:


  • Blama
    replied
    Hi Isomorphic,

    the last post is just about validator.addErrorMessageVariable("errorMessage", myLocalizedErrorMessage). I found a related thread, which unfortunately does not help.


    The return new DSResponse().setFailure(myLocalizedMessage) is working as expected, thank you.
    For anyone interested:
    Code:
    public class I18n {
        public static String getString(String key, HttpServletRequest httpServletRequest) {
            /* Use the following line in development, when you want to add strings in a running Tomcat instance without restarting Tomcat */
            // ResourceBundle.clearCache();
            ResourceBundle labels = null;
            // Find the first matching language from the request
            for (Enumeration<Locale> e = httpServletRequest.getLocales(); e.hasMoreElements();) {
                Locale currentLocale = e.nextElement();
                labels = ResourceBundle.getBundle("com.mypackage.server.i18n.I18n", currentLocale);
                if (labels.getLocale().getLanguage().equals(currentLocale.getLanguage()))
                    break;
            }
            return labels.getString(key);
        }
    }
    Plus files I18n_??-utf8.properties and following ant-target:
    Code:
            <echo>Converting server i18n files (UTF-8 to ASCII)</echo>
            <exec executable="${java.sdk}/bin/native2ascii.exe">
                <arg value="-encoding" />
                <arg value="UTF-8" />
                <arg value="${basedir}/src/com/mypackage/server/i18n/I18n_de-utf8.properties" />
                <arg value="${basedir}/src/com/mypackage/server/i18n/I18n_de.properties" />
            </exec>
            <exec executable="${java.sdk}/bin/native2ascii.exe">
                <arg value="-encoding" />
                <arg value="UTF-8" />
                <arg value="${basedir}/src/com/mypackage/server/i18n/I18n_en-utf8.properties" />
                <arg value="${basedir}/src/com/mypackage/server/i18n/I18n_en.properties" />
            </exec>
    Thank you & Best regards
    Blama
    Last edited by Blama; 10th Dec 2015, 07:17.

    Leave a comment:


  • Blama
    replied
    Hi Isomorphic,

    how can I do the same thing for serverside DMI validation?

    The signature of my DMI validator is:
    Code:
    public boolean condition(Object value, Validator validator, String fieldName, Map<Object, Object> record, DataSource ds)
    I can't get the request's locale here, can I? validator.getLanguage() is completely unrelated.

    I want to to this:
    Code:
    validator.addErrorMessageVariable("errorMessage", myLocalizedErrorMessage);
    Best regards
    Blama

    Leave a comment:


  • Isomorphic
    replied
    Use standard Java techniques - the current Locale is accessible from the ServletRequest.

    Leave a comment:


  • Blama
    replied
    Hi Isomorphic,

    I saw that. Sorry for not being more clear.
    I meant DMI Validation or DSResponse-Errormessages like return new DSResponse().setFailure(myLocalizedMessage);

    So where I return from Java code, but have the incoming DSRequest and HttpServletRequest available.

    Best regards
    Blama

    Leave a comment:


  • Isomorphic
    replied
    Hi Blama,
    Did you see the docs here?

    Regards
    Isomorphic Software

    Leave a comment:

Working...
X