如何在外部 javascript 文件中使用 EL

发布于 2024-12-22 10:09:06 字数 227 浏览 3 评论 0原文

我有一个在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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

玻璃人 2024-12-29 10:09:06

您只需为外部java脚本的函数声明一些输入参数即可。在JSF中调用外部java脚本的函数时,您可以使用EL表达式来访问bean中的值并将它们传递给外部java脚本' s 函数。

像这样:

function someExternalJsFunction(var1,var2,...,varX)
{

}

然后在 JSF 中:

<h:commandLink action="....."  
onclick="someExternalJsFunction(#{request.contextPath},#{myBackingBean.myProperty},....)"/> 

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:

function someExternalJsFunction(var1,var2,...,varX)
{

}

Then in the JSF:

<h:commandLink action="....."  
onclick="someExternalJsFunction(#{request.contextPath},#{myBackingBean.myProperty},....)"/> 
澉约 2024-12-29 10:09:06

这不是一件容易的事。但是您可以利用 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文