简体   繁体   中英

How to use JavaScript inside EL expression (ui:param with value)

I want to be able to pass a value of javascript function to an ui:parameter like this:

<ui:param name="paramName" value="someWidget.function()"/>

But this obviously does not work (it thinks that: someWidget.function() is a string parameter).

If I try:

<ui:param name="paramName" value="#{someWidget.function()}"/>

It thinks that someWidget is a bean name.

Is there any way to place there a value of javascript function on a widget? If not, what would be ideal way of including a value of javascript function in a parameter in JSF?

There's a major conceptual misunderstanding going on. JSF runs in webserver and produces a HTML page with therein some CSS/JS code which get delivered to the webbrowser. That HTML page with CSS/JS in turn runs in webbrowser. JS thus definitely doesn't run in webserver "in sync" with JSF somehow. To JSF, JS is like HTML just part of template text which it needs to produce.

You need to look for the solution in a different direction. As the concrete functional requirement is unclear, I can't give any hints in the right direction nor kickoff examples. To the point, you should perform it in Java instead of JS, or to let JS during page load send an ajax request with the desired variable as request parameter.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM