使用JSF从资源包传递本地化的javascript消息 [英] Passing localized javascript messages from resource bundles using JSF

查看:66
本文介绍了使用JSF从资源包传递本地化的javascript消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经使用JSF构建了一个应用程序,服务器发出的所有消息都使用资源包进行了本地化。

I have built an application with JSF and all messages issued by the server are localized with resource bundles.

我的问题是:如何获取客户端发出的消息浏览器使用javascipt本地化存储在资源包中的消息?

My question is: how to get messages issued in the client browser with javascipt localized with the messages stored in the resource bundles?

我是否必须动态生成javascript,如果是这样,怎么办?

Do I have to generate javascript dynamically and if so how can this be done?

例如,我如何让服务器在以下表单验证方法中本地化«alert»javascript消息:

For example, how can I have the server localize the «alert» javascript message in the following form validation method:

function valider() {
    typeActionRadio = document.getElementById("membres_editer_creer:typeActionAdr");
    if (typeActionRadio.style.display == "block") {
        var boutonsRadio = document.forms["membres_editer_creer"]["membres_editer_creer:typeActionAdr"];
        for ( var i = 0; i < boutonsRadio.length; i++)
             if (boutonsRadio.item(i).checked) return true;
    }
     alert ("Vous devez indiquer la raison du changement d'adresse (bouton radio à sélectionner).");
    return false;
}


推荐答案

让JSF打印出所需的JS代码。例如,

Just let JSF print the desired JS code. E.g.

<script>
    var message = "#{bundle['some.key']}";
</script>

您只需要考虑单个引号和换行符等JS特殊字符。为此,您可以注册自定义EL功能代表 Apache Commons Lang StringEscapeUtils ,或使用 OmniFaces of:escapeJS() 功能。

You only need to take JS special characters such as singlequotes and newlines into account. For that, you could register a custom EL function which delegates to Apache Commons Lang StringEscapeUtils, or use OmniFaces of:escapeJS() function.

这篇关于使用JSF从资源包传递本地化的javascript消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆