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

5
  • 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". Commented Mar 30, 2012 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 <script language="javascript" src="ajax.googleapis.com/ajax/libs/jquery/1.7.1/…> TAKE a look at the way I included the jQuery in the following answer... stackoverflow.com/a/9439565/617373 Commented Mar 30, 2012 at 20:02
  • Thank tou Daniel for the help, Commented Mar 30, 2012 at 23:11
  • Thank you BalusC for the comment, the library value "JavaScript" is the directory name not the name of the language Commented Mar 30, 2012 at 23:12
  • but how can refere to the jquery libs localy ? Commented Mar 30, 2012 at 23:42

1 Answer 1

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.

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

Comments

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.