3

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?

Mahmoud Saleh
  • 33,303
  • 119
  • 337
  • 498

2 Answers2

3

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},....)"/> 
Ken Chan
  • 84,777
  • 26
  • 143
  • 172
  • 1
    i used this solution and it sounds good, but BTW the el inside the javascript call needs to be surrounded by single quotes. – Mahmoud Saleh Dec 21 '11 at 10:26
0

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.

yatskevich
  • 2,085
  • 16
  • 25