4

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!

1 Answer 1

9

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.

Sign up to request clarification or add additional context in comments.

1 Comment

@Ben - it seems you're right, but only in the circumstance of the attribute name not being present. From the documentation: If there is no name attribute and the argument component does have children, the renderer must ensure that those children are encoded as usual.. Still, it should not be enclosed in the script tag...

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.