{"id":986,"date":"2010-11-04T13:54:21","date_gmt":"2010-11-04T13:54:21","guid":{"rendered":"http:\/\/salientsoft.co.uk\/?p=986"},"modified":"2010-11-04T14:08:48","modified_gmt":"2010-11-04T14:08:48","slug":"how-to-add-inline-javascript-to-a-faceletsxhtml-page","status":"publish","type":"post","link":"https:\/\/salientsoft.co.uk\/?p=986","title":{"rendered":"How to add inline Javascript to a Facelets\/XHTML page"},"content":{"rendered":"<p>This is not immediately obvious; the following are the key points:-<\/p>\n<ul>\n<li>The Javascript code between the script tags needs to be embedded in XML \u201cCDATA\u201d sections<\/li>\n<li>The CDATA open and close tags need to be preceded with Javascript comment markers \u201c\/\/\u201d<\/li>\n<li>You can freely use JSF Expression language within the Javascript and it will be evaluated and inserted (as with the \u201crequest.contextPath\u201d below)<\/li>\n<\/ul>\n<p>The following example xhtml page illustrates this:-<\/p>\n<p style=\"padding-left: 30px;\">&lt;!DOCTYPE HTML&gt;<br \/>\n&lt;html xmlns=&#8217;<a href=\"http:\/\/www.w3c.org\/1999\/xhtml'\">http:\/\/www.w3c.org\/1999\/xhtml&#8217;<\/a><br \/>\n\u00a0\u00a0 xmlns:f=&#8217;<a href=\"http:\/\/java.sun.com\/jsf\/core'\">http:\/\/java.sun.com\/jsf\/core&#8217;<\/a><br \/>\n\u00a0\u00a0 xmlns:h=&#8217;<a href=\"http:\/\/java.sun.com\/jsf\/html'\">http:\/\/java.sun.com\/jsf\/html&#8217;<\/a>&gt;<br \/>\n&lt;f:view contentType=&#8221;text\/html&#8221;&gt;<br \/>\n&lt;h:head&gt;<br \/>\n&lt;script type=&#8221;text\/javascript&#8221;&gt;<br \/>\n\/\/&lt;![CDATA[<br \/>\n\u00a0\u00a0\u00a0 alert(&#8220;Hello World from #{request.contextPath}&#8221;);<br \/>\n\/\/]]&gt;<br \/>\n&lt;\/script&gt;<br \/>\n&lt;\/h:head&gt;<br \/>\n&lt;h:body&gt;&lt;\/h:body&gt;<br \/>\n&lt;\/f:view&gt;<br \/>\n&lt;\/html&gt;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This is not immediately obvious; the following are the key points:- The Javascript code between the script tags needs to be embedded in XML \u201cCDATA\u201d sections The CDATA open and close tags need to be preceded with Javascript comment markers \u201c\/\/\u201d You can freely use JSF Expression language within the Javascript and it will be [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[22],"tags":[76,40,78,184,16],"_links":{"self":[{"href":"https:\/\/salientsoft.co.uk\/index.php?rest_route=\/wp\/v2\/posts\/986"}],"collection":[{"href":"https:\/\/salientsoft.co.uk\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/salientsoft.co.uk\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/salientsoft.co.uk\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/salientsoft.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=986"}],"version-history":[{"count":12,"href":"https:\/\/salientsoft.co.uk\/index.php?rest_route=\/wp\/v2\/posts\/986\/revisions"}],"predecessor-version":[{"id":991,"href":"https:\/\/salientsoft.co.uk\/index.php?rest_route=\/wp\/v2\/posts\/986\/revisions\/991"}],"wp:attachment":[{"href":"https:\/\/salientsoft.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=986"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/salientsoft.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=986"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/salientsoft.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=986"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}