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?

1

2 Answers 2

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},....)"/> 
Sign up to request clarification or add additional context in comments.

1 Comment

i used this solution and it sounds good, but BTW the el inside the javascript call needs to be surrounded by single quotes.
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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.