0

Well, title says it all, I want syntax highlighting inside <h:outputScript> tags, for example:

  <?xml version="1.0" encoding="utf-8"?>
  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

  <ui:composition xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:c="http://java.sun.com/jsp/jstl/core"
      xmlns:t="http://myfaces.apache.org/tomahawk">

      <h:panelGroup id="foo">
          blah
      </h:panelGroup>

      <h:outputScript>

        //please highlighting here
        var iousGoogleSearchesLaterIfearThereIsNoSuch = function(but, I, do, want, so) {
           if(youKnow(something)) {
             please(but);
           }
           for (I, do, so, want ;'';);
           return "the favor" && share;
        };

      </h:outputScript>

  </ui:composition>

Any tips/tools or ideas? Thanks

user777
  • 906
  • 5
  • 16
  • It's more efficient and better practice to put JS code in a JS file. – BalusC Feb 10 '16 at 18:33
  • @BalusC definitely agreed, and that's what I do like 99% of the cases, but sometimes not an option – user777 Feb 10 '16 at 18:38
  • If it's solely the EL evaluation, this may be helpful: http://stackoverflow.com/q/34156641 As to the concrete problem, what if you just use ` – BalusC Feb 10 '16 at 18:45
  • @BalusC whoa that ` – user777 Feb 10 '16 at 18:50

1 Answers1

3

Given that you don't really take advantage of <h:outputScript> component (especially relocation by target="head|body" attribute and being able to grab and manipulate it via the component tree), simply use plain HTML <script> instead.

<script type="text/javascript">
    ...
</script>

It would be better if you switch to HTML5 doctype, then you don't need to specify type attribute too.

<!DOCTYPE html>
...
<script>
    ...
</script>

Nonetheless, putting JS code in its own JS file is more efficient (browser has opportunity to cache it, so overall performance is better) and is considered best practice as to separation of concerns.

See also:

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • Great answer! Thank you. Could you possibly elaborate on or link to a resource detailing the benefits of `` over ` – user777 Feb 10 '16 at 19:00
  • This? http://stackoverflow.com/questions/8367421 and this http://showcase.omnifaces.org/resourcehandlers/CombinedResourceHandler – BalusC Feb 10 '16 at 19:14