Pass parameters to messages from resource bundle to components other than **h:outputFormat**

前端 未结 3 1999
北荒
北荒 2020-12-16 18:10

Is there a convenient way to pass parameters to messages from resource bundle to components other than h:outputFormat?

For instance, this is legal:

3条回答
  •  余生分开走
    2020-12-16 18:46

    How about this approach ?

    EL expression allow you to define a function .You first define a EL expression 's function , which accepts a resource bundle , its message key and placeholder 's parameter and output the resolved message .

    public static String geti18nMsg(ResourceBundle bundle ,String msgKey, String paramValue ) {
        String  msgValue = bundle.getString(msgKey);
        MessageFormat   messageFormat = new MessageFormat(msgValue);
        Object[] args = {paramValue};
        return messageFormat.format(args);
    }
    

    Then call this function to get the resolved message in the :

    
    

提交回复
热议问题