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
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
This was a minor defect and fixed in 3.2. final;
http://code.google.com/p/primefaces/issues/detail?id=3670
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.
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...
You need to add the PrimeFaces namespace.
xmlns:p="http://primefaces.org/ui"
Have a look at the PrimeFaces Getting Started guide.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With