0

i am trying to use some jquery component with jsf project, the error is :

Erreur : $ is not defined

here is the source code of my xhtm page :

<?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">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html">

<h:head>
<h:outputScript library="javascript" name=jquery-1.7.1.js target="body" />
<h:outputScript library="javascript" name="jquery.mcdropdown.js" target="body" />
<h:outputScript library="javascript" name="jquery.bgiframe.js" target="body" />
<h:outputStylesheet name="jquery.mcdropdown.css" library="css" />
<h:outputStylesheet name="style.css" library="css" />
<script type="text/javascript"> 
$(document).ready(function (){ 
$("#category").mcDropdown("#categorymenu"); 
$("#category").dblclick(function(){

});
}); 
</script>
</h:head>

<h:body>

<h1>JSF 2.0 and Resources example</h1>

<h:outputText styleClass="red-color"
    value="This is a Message (Red color)" />

<br />
<h:graphicImage library="images" name="sofa.png" />

<h:inputText id="category" value="" label="Menu"></h:inputText>

</h:body>

</html>

Blockquote

freesniper
  • 79
  • 1
  • 9
  • Unrelated to the problem, while it "works", the way how you use the `library` attribute is completely wrong. It should denote the theme/module name, not the file type (think once again, this is already represented by tag name "outputScript", "outputStylesheet" and "graphicImage"). Remove `library` and put its value in `name` like so `name="javascript/jquery-1.7.1.js"`, `name="css/style.css"` and `name="images/sofa.png"`. – BalusC Mar 30 '12 at 19:30
  • till you figure out whats wrong with the way you placed the jquery file and ref to in replace the h:outputscript with this TAKE a look at the way I included the jQuery in the following answer... http://stackoverflow.com/a/9439565/617373 – Daniel Mar 30 '12 at 20:02
  • Thank tou Daniel for the help, – freesniper Mar 30 '12 at 23:11
  • Thank you BalusC for the comment, the library value "JavaScript" is the directory name not the name of the language – freesniper Mar 30 '12 at 23:12
  • but how can refere to the jquery libs localy ? – freesniper Mar 30 '12 at 23:42

1 Answers1

1

JQuery library did not load properly. Could be you're missing quotes around its name in name="jquery-1.7.1.js". I am also not sure whether you can refer to $ in head while scripts have target body.

mrembisz
  • 12,722
  • 7
  • 36
  • 32