我正在尝试使用 OmniFaces 来推迟 PrimeFaces 脚本,如本答案所示。
但是 PrimeFaces 在 head 中渲染了一个内联脚本,就像这样(脚本美化并由我评论):
<script type="text/javascript">
if(window.PrimeFaces) {
// this line is always rendered in Development mode.
PrimeFaces.settings.projectStage='Development';
// these lines are added if Client Side Validation is enabled.
PrimeFaces.settings.locale='pt_BR';
PrimeFaces.settings.validateEmptyFields=true;
PrimeFaces.settings.considerEmptyStringNull=true;
}
</script>
当我运行应用程序时,我得到一些 JS 错误(文件和错误):
validation.js.xhtml?ln=primefaces&v=5.3:1
Uncaught TypeError: Cannot read property 'en_US' of undefined
beanvalidation.js.xhtml?ln=primefaces&v=5.3:1
Uncaught TypeError: Cannot read property 'en_US' of undefined
produto.xhtml:2
Uncaught TypeError: Cannot set property 'locale' of undefined
如果我把一些变量放进去primefaces.deferred.js
,像这样:
if (!primeFacesLoaded) {
window.PrimeFaces = {
// variables added - begin
settings: {
projectStage: 'Development',
locale: 'pt_BR',
validateEmptyFields: true,
considerEmptyStringNull: true
},
// variables added - end
ab: function () {
defer("ab", arguments);
},
cw: function () {
defer("cw", arguments);
},
focus: function () {
defer("focus", arguments);
}
};
}
前两个错误仍然发生,但第三个错误消失了。
显然,PrimeFaces JS 对象缺少以下属性:
locales: {
// other values...
en_US: {
// other values...
}
},
util: {
// other values...
},
所以,问题是:如何正确地推迟这些 PrimeFaces 脚本属性?
PS:版本:PrimeFaces 5.3、OmniFaces 2.3、Payara Server (Glassfish) 4.1.1.161