如何在外部 javascript 文件中使用 EL
我有一个在xhtml页面中定义的javascript函数,并且我能够在其中使用EL,现在当我将该函数移动到外部JS文件时,我我无法像这样使用 EL:
#{request.contextPath}
#{myBackingBean.myProperty}
所以,我想知道如何在外部 JS 中完成类似的事情?
i have a javascript function that was defined in the xhtml page, and i was able to use EL inside it, now when i moved the function to an external JS file, i am not able to use EL like:
#{request.contextPath}
#{myBackingBean.myProperty}
so, i was wondering how to accomplish something like that in external JS?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您只需为外部java脚本的函数声明一些输入参数即可。在JSF中调用外部java脚本的函数时,您可以使用EL表达式来访问bean中的值并将它们传递给外部java脚本' s 函数。
像这样:
然后在 JSF 中:
You can just declare some input parameters for the external java script 's function .When calling the external java script 's function in JSF , you can use the EL expression to access the values from the beans and pass them to the external java script 's function.
Something like this:
Then in the JSF:
这不是一件容易的事。但是您可以利用 HTML5
data-*
属性并放置你的 EL 表达式在那里,稍后从 JavaScript 中读取它们。It's not an easy task. But you can leverage HTML5
data-*
attributes and put your EL expressions in there and read them from JavaScript later.