JSF/ Javascript error - jsf

I have developed a JSF 2.0 application in Netbeans IDE which is working correctly in my browser but when I deployed it on client side , it is giving me error: PRIMEFACES IS UNDEFINED
Does anyone have idea about the error? Any help will be highly appreciated. Thanks!

If you didnt have a head tag you will get that error.
You need to add the PrimeFaces namespace at the head tag.
xmlns:p="http://primefaces.org/ui"
Your xhtml page should like this-
<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>
<p:spinner />
</h:body>
</html>
Please have a look at PrimeFAQ #2 and PrimeStartGuide.

Related

Why doesn't PrimeFaces contentFlow tag work?

I tried to use primeFaces contentFlow in jsf 2.3 but it doesn't load any images, just it shows me "loading"
the xhtml code is:
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://xmlns.jcp.org/jsf/core"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:p="http://primefaces.org/ui"
xmlns:c="http://java.sun.com/jsp/jstl/core">
<h:head>
</h:head>
<h:body>
<p:contentFlow value="#{imagesView.images}" var="image">
<p:graphicImage name="demo/images/nature/#{image}" styleClass="content"/>
<div class="caption">#{image}</div>
</p:contentFlow>
...
and after render it appears so:
i tested it on primefaces versions 6.2 to 10. what can be the problem? does it need other libraries or extensions?

JSF: How to insert something into a custom facelets tag?

I have created a custom facelets tag file, but I'm struggeling to insert something into it. This is the tag:
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:ui="http://java.sun.com/jsf/facelets">
<h1>TestTag</h1>
<ui:insert name="foo"/>
</ui:composition>
This is how I expect to use it:
<ds:testtag>
<ui:define name="foo">
<h2>TestInsert</h2>
</ui:define>
</ds:testtag>
Of course, I have created a taglib file and registered it in web.xml. The ds: namespace is also declared in the file where I want to use the tag.
On the rendered result I can see the TestTag caption from the tag itself, but not the inserted TestInsert.
The answer to this question How to create a custom Facelets tag? as well as a comment here How to create a composite component for a datatable column? suggests that it is possible to insert something into a tag; unfortunately, I couldn't find a working example. What am I missing?
Try this (not tested):
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:ui="http://java.sun.com/jsf/facelets">
<h1>TestTag</h1>
<ui:insert />
</ui:composition>
And use component like this:
<ds:testtag>
<h2>TestInsert</h2>
</ds:testtag>
You need insert into component a tag:
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:ui="http://java.sun.com/jsf/facelets">
<h1>TestTag</h1>
<ui:insertChildren/>
</ui:composition>
And when use it like this:
<ds:testtag>
<h2>TestInsert</h2>
</ds:testtag>
Also you may use
<composite:insertChildren/>
Don't forget for right imports
xmlns:composite="http://java.sun.com/jsf/composite"
or
xmlns:ui="http://java.sun.com/jsf/composite"

tag calendar in primefaces not display in navigator

i am beginner in jsf and when i use tag calendar it's not display in Navigator and any error appear ; i use eclipce , jsf 2 , primefaces 4
here my code view :
<?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"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:p="http://primefaces.org/ui">
<h:body>
<h:form>
<p:calendar value="#{ticket.dateCreation}" mode="inline" />
</h:form>
</h:body>
</html>
Since JSF 2.2 you should use the new namespaces:
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:f="http://xmlns.jcp.org/jsf/core"
xmlns:p="http://primefaces.org/ui">
You should also include
<h:head>
</h:head>
just below the namespaces so Primefaces can include Javascript/CSS resources.
I hope you're not referring to Netscape Navigator :-)

JSF Javascript failure - myfaces not defined

I'm working on a web solution using myfaces and primefaces. We have several pages in our solution, and some of the get this mystical error myfaces not defined because there is a javascript file that is not included on the page, namely the jsf.js file:
<script type="text/javascript" src="/driwkraft-hig/javax.faces.resource/jsf.js.xhtml?ln=javax.faces&stage=Development">
The error occurs when clicking on certain commandlinks on the page, where the generated javascript has been set to onClick="myfaces.oam.submitForm...
Now, I understand that this is something that the JSF framework adds to the page based on some mystical criteria which I fail to understand. There are pages that appear to be equal with regards to what elements are used, and it succeeds on one and fails on the other.
I have tried to create a test-file where I copied content of one of the failing pages and then removed parts until it would work to figure out what was the source of the problem, but this did not give me anything. My next hunch is that it might be some configuration-error somewhere. But I am completely and utterly blank as to where to start.
I understand I should probable add some code or xml in to this question, but I cannot post the entire solution so I think it is best to do so upon request. Would the web.xml be useful? How about the faces-config.xml?
Any guidance and thoughts are much appreciated!
Edit - adding template
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:ui="http://java.sun.com/jsf/facelets">
<ui:insert name="metadata" />
<h:head>
....
<title>
<ui:insert name="title">
....
</ui:insert>
</title>
</h:head>
<h:body>
....
<ui:insert name="content">
....
</ui:insert>
...
</h:body>
</html>
Edit - adding template client
<!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:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:p="http://primefaces.org/ui"
xmlns:dp="http://java.sun.com/jsf/composite/dapsys">
<ui:composition template="/templates/default.xhtml">
<ui:define name="title">TITLE</ui:define>
<ui:define name="metadata">
<f:metadata>
<f:viewParam name="customerId" value="#{CustomerController.customerId}">
</f:viewParam>
<f:viewParam name="edit" value="#{CustomerController.edit}">
</f:viewParam>
<f:viewParam name="activeTab" value="#{CustomerController.activeTab}">
</f:viewParam>
</f:metadata>
</ui:define>
<ui:define name="content">
...
</ui:define>
</ui:composition>
</html>
It's auto-included if there's a <h:head> in the template which automatically renders CSS/JS dependencies from UIViewRoot#getComponentResources() which are added via #ResourceDependency annotation on the JSF component.
Those problem symptoms suggests that there's no <h:head> in the template, but a plain <head>. Therefore JSF is unable to auto-include CSS/JS resource dependencies which in turn causes this JS error.
To fix this problem, just make sure that there's a <h:head> instead of <head> in the template.
<!DOCTYPE html>
<html lang="en"
xmlns="http://www.w3.org/1999/xhtml"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:ui="http://java.sun.com/jsf/facelets">
<h:head> <!-- Look here. -->
<title>Blah</title>
</h:head>
<h:body>
<h1>Blah</h1>
<p>Blah blah.</p>
</h:body>
</html>

When using MyFaces 2.1, with Eclipse Juno, how do I get rid of a space after the doctype

I have searched all around for an answer, and tried many things, but no luck. When I use MyFaces 2.1 with Eclipse Juno, and attempt to create an HTML5 page, I get
<!DOCTYTPE html >
Notice the space after the "html". When this page is viewed in FireFox, using HTML Tidy, it throws an error saying its an invalid doctype.
The source xhtml file contains with no space. Does anyone have a solution?
Thanks
Dan
I can reproduce it in at least MyFaces 2.1.9 and 2.1.10 (didn't tried older versions). This problem doesn't manifest in Mojarra. It's undoubtedly a bug in MyFaces. I recommend to report it to MyFaces guys.
For the meantime until they get it fixed, I found a workaround. Replace <!DOCTYPE>
<!DOCTYPE html>
<html lang="en"
xmlns="http://www.w3.org/1999/xhtml"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:ui="http://java.sun.com/jsf/facelets"
>
...
</html>
by <h:doctype>
<ui:composition
xmlns="http://www.w3.org/1999/xhtml"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:ui="http://java.sun.com/jsf/facelets"
>
<h:doctype rootElement="html" />
<html lang="en">
...
</html>
</ui:composition>
Its renderer generates the proper space-less doctype.
This problem is in no way related to Eclipse. It's just a tool like Notepad.

Resources