0 Replies Latest reply on Sep 8, 2011 12:04 PM by madjack59

    'RichFaces' is undefined

    madjack59 Newbie

      We recently upgraded to RichFaces 4.0.0. In the past, we had loaded the JQuery library as a separate library. The version included in the RichFaces 4 JAR is current enough, so we decided to just use it.


      In searching for a way to expose the JQuery core JavaScript library to the app, I found a recommended approach is to include a <rich:jQuery... /> tag in <h:head>. I don't really need this tag to do any work; I just want JQuery to be available to our app. So I declared a tag in <h:head> like this:


      <rich:jQuery />


      This causes the following to be rendered in the <head> element of the page:


      <span id="j_idt7" style="display: none;">

          <script type="text/javascript">RichFaces.jQuery.query();</script>



      1) Is this the best way to have RichFaces render the script tag(s) to load JQuery?


      With that, our JavaScript code is able to make calls to jQuery functions with no issues.  In Firefox, we get no JavaScript warnings. However in IE8, we get a JavaScript warning that 'RichFaces' is undefined:




      When reviewing the rendered source in both IE and Firefox, there is indeed no rendered script element before the RichFaces.jQuery.query() call that could satisfy the RichFaces JavaScript reference. I suspect this is why IE is complaining.


      However, there are a couple of <script> elements after the <rich:jQuery .../> that indicate the jQuery libraries are being loaded:


      <span id="j_idt7" style="display: none;">

         <script type="text/javascript">RichFaces.jQuery.query();</script>


      <script type="text/javascript" src="/app/javax.faces.resource/jquery.js.xhtml"></script>

      <script type="text/javascript" src="/app/javax.faces.resource/jquery.component.js.xhtml?ln=org.richfaces"></script>


      2) What do we need to do to make this IE error go away?


      Finally, I'd like to suggest that an empty <rich:jQuery /> tag simply render the <script> elements needed to load JQuery and avoid the empty RichFaces.jQuery.query() call. It's doing nothing useful for us, but seems to cause this problem.