Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"PrimeFaces is not defined" error

I am trying to print using the PrimeFaces printer functionality. I have created a new GlassFish 3 Java EE project and added the PrimeFaces 3.1.1 .jar file.

The code I am using currently is as follows:

<html xmlns="http://www.w3.org/1999/xhtml" 
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:p="http://primefaces.org/ui">

  <h:head>
    <title>Facelet Title</title>
  </h:head>
  <h:body>
    <h:form>
      <h:outputText id="a" value="AA" />
      <h:commandLink id="btn" value="Print">
        <p:printer target="a" />
      </h:commandLink>
    </h:form>
  </h:body>
</html>

Unfortunately, the print function isn't working. Instead, the FireBug console shows me the following error:

PrimeFaces is not defined

like image 756
Eric Avatar asked Mar 07 '12 14:03

Eric


6 Answers

If you didnt have a head tag you will get that error.

Primefaces requires a head tag to work.

See #2 on their faq

http://primefaces.org/faq.html

like image 184
Newton Avatar answered Oct 05 '22 23:10

Newton


This was a minor defect and fixed in 3.2. final;

http://code.google.com/p/primefaces/issues/detail?id=3670

like image 29
Cagatay Civici Avatar answered Oct 05 '22 22:10

Cagatay Civici


This will also happen if you are not allowing access to

${webapp}/javax.faces.resources/**

Check your security XML configuration.

The JavaScript error that Primefaces is not defined.

like image 37
Nicholas DiPiazza Avatar answered Oct 05 '22 22:10

Nicholas DiPiazza


try this... (if this does not work its probably a bug - open a ticket on issue tracker...)

<html xmlns="http://www.w3.org/1999/xhtml"  
    xmlns:h="http://java.sun.com/jsf/html"  
    xmlns:f="http://java.sun.com/jsf/core"  
    xmlns:p="http://primefaces.org/ui">  

    <h:head>  

    </h:head>  

    <h:body>  
     <h:form>
      <h:commandButton id="btn" value="Print">
        <p:printer target="output" />
      </h:commandButton>
      <h:outputText id="output" value="PrimeFaces Rocks!" />

      <h:outputLink id="lnk" value="#">
          <p:printer target="image" />
          <h:outputText value="Print Image" />
      </h:outputLink>
      <p:graphicImage id="image" value="/images/nature1.jpg" />

      </h:form>   
    </h:body>  
</html>  

listen... primefaces are using the jqprint jquery plugin.... You might be better try use it directly while waiting for a official primefaces response...

like image 29
Daniel Avatar answered Oct 05 '22 22:10

Daniel


You need to add the PrimeFaces namespace.

xmlns:p="http://primefaces.org/ui"  

Have a look at the PrimeFaces Getting Started guide.

like image 34
Dave Webb Avatar answered Oct 05 '22 23:10

Dave Webb


I have the same problem if I only use a p:calendar on a form. All tags on the view are jsf/facelet tags. The only primefaces tag is the calendar. It looks as if the java-script is removed as an optimization ?

If I add more tags as a p:dataTable the java script errors disappear and the calendar component works. Perhaps this will point you some where. As a workaround you could a p:dataTable on the form with rendered=false.

like image 44
KlaasJan Elzinga Avatar answered Oct 05 '22 23:10

KlaasJan Elzinga