Mahmoud Saleh
Mahmoud Saleh

Reputation: 33605

How to use EL in external javascript file

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?

Upvotes: 3

Views: 4923

Answers (2)

Ken Chan
Ken Chan

Reputation: 90447

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},....)"/> 

Upvotes: 3

yatskevich
yatskevich

Reputation: 2093

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.

Upvotes: 0

Related Questions