Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using <h:outputScript> to add javascript code in JSF

I'm trying to run some basic javascript code with JSF 2. I'm using the following code to do so:

<h:outputScript target="head">
    var props = $.event.props;
</h:outputScript>

Looking at the source of the page I can't find any evidence of this code. I thought that was the correct way to work with javascript code in JSF. Should I use the <script> tag of html instead?

Thanks!

like image 338
Ben Avatar asked Jan 17 '23 18:01

Ben


1 Answers

That's not the intend purpose of the outputScript tag. It just renders an HTML script tag while resolving the location of the javascript file that's specified in its name attribute.

If you need to inline javascript, just enclose it in the <script> tag directly.

like image 194
lsoliveira Avatar answered Jan 27 '23 19:01

lsoliveira