PrimeFaces components don't appear in browser - jsf

I'm using JSF 2.2 in my Project (Tomcat 7.42, Mojarra 2.2.1), and i want to use p:calendar from PrimeFaces library. I have included primefaces-4.0.jar into my Project Libraries, and add xmlns:p="http://primefaces.org/ui" namespace, and everything looks ok. Here is my code:
<?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:ui="http://java.sun.com/jsf/facelets"
xmlns:p="http://primefaces.org/ui">
<h:body>
<p:calendar value="#{calendarBean.date2}" id="popupCal" />
</h:body>
</html>
But, in browser, calendar doesn't appear. Standard h: components work great, but from PrimeFaces - nothing works.
I know that PF 4.0 should support JSF 2.2, but i have some issue.
I appreciate any help?

In jsf 2.2 namespaces are changed so you shoud use xmlns.jcp.org instead of java.sun.com

I managed to solve the problem! I am really sorry, but a PrimeFaces' "Getting Started" really confused me. The problem is that I had added PrimeFaces as a library into build path of my project, which is not correct. The right way is to put primefaces-4.0.jar into lib folder under web project. Things are better now. Anyway, thanks people.

Related

ui:include includes wrong file in JSF 2.2

Accorrding to the documentation of ui:include tag
Use this tag—which is very similar to JSP's jsp:include—to encapsulate
and reuse content among multiple XHTML pages. There are three things
this tag can include: plain XHTML, and XHTML pages that have either a
composition tag or a component tag.
You supply a filename, through ui:include's src attribute for JSF to
include. That filename is relative to the XHTML file that was rendered
as a result of the last request. So, for example, if JSF loaded the
view login.xhtml, and that file included pageDecorations/header.xhtml,
and pageDecorations/header.xhtml included companyLogo.xhtml, then
companyLogo.xhtml will not be found if it's in the pageDecorations
directory, because companyLogo.xhtml has to be in the same directory
as login.xhtml.
I created a simple test:
webapp/login.xhtml
<!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:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html">
<h:body>
<ui:include src="pageDecorations/header.xhtml" />
</h:body>
</html>
webapp/pageDecorations/header.xhtml
<ui:include
src="logo.xhtml"
xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
/>
webapp/pageDecorations/logo.xhtml
<h:outputText
value="Logo in /pageDecorations"
xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
/>
webapp/logo.xhtml
<h:outputText value="Logo in /"
xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
/>
When I ran this test (loaded login.xhtml page) using JSF 2.2 on WildFly 10.1 , I got Logo in /pageDecorations, while according to the documentation it should be: Logo in /
What is wrong ? Is there a bug in the documentation or Mojarra implementation ? Or my understanding is wrong ?
First, you are inside webapp/ and executing webapp/login.xhtml
inside that you get src="pageDecorations/header.xhtml" and for exectuing that you are in pageDecorations and from header.xhtml you are tring to find src="logo.xhtml" which will you get in the same directory (pageDecorations) so it will print
"Logo in /pageDecorations" .
Document looks wrong in this case.

jsf - facelets - pack library jar with *.xhtml-s and beans only

I could read the tutorial which describes how to pack facelets to jar to reuse tags as library...
The thing is the instruction recommends using both JSP and JSF in manner as (see code snippet);
<jsp:root xmlns:jsp="http://java.sun.com/JSP/Page"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:c="http://java.sun.com/jstl/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core" version="2.0">
<ui:composition>
...
</ui:composition>
</jsp:root>
...and using both .taglib.xml + .tld conf files... :(
So I don't get it may ui:composition in *.xhtml be started as usual by (see code snippet) ...
<ui:composition
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:c="http://java.sun.com/jstl/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core" version="2.0">
...
</ui:composition>
...not to deal with jsp at all? And if, yes, how this kind of library can be added to dynamic web project in eclipse for example?
So my question concerning the tutorial is...
A) is there a way to avoid using *.tld and use have *.taglib.xml only for the lib if the tag library will contain xhtml files only?
B) is there a way to have xhtml-s in non META-INF sub-folder but in some random one?
C) How to automate this kind of library creation process? I mean should I create a project in eclipse (?project category) to have correct folders structure by default to make possible re-compile it and test it and only after that pack it as a jsf library?
I googled a lot but couldn't find solutions variations so please share your experience;
Thanks

Unknown jsf tag in xhtml page in jsf application

This is my first application with eclipse and jsf and i having some problems.
Here is my project structure:
eclipse project structure
I have downloaded and used JSF 2.1 (Mojarra 2.1.6-FCS) jar file and there is only a single jar file in that and i have used that jar file as a user library.
Now the problem i am facing is that when i use h:head in my index.xhtml file it shows that h:head is an unkown tag.Of course i am using anugular brackets. besides h:head , i am not able to type that in here.
here is my index.xhtml file:
<?xml version="1.0" encoding="ISO-8859-1" ?>
<!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">
<h:head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<title>Insert title here</title>
</h:head>
<body>
</body>
</html>
What is wrong here? IS there only one jar file file to be included?
also there are some white packages marks in the jar file i included...here they are:
while package in jar
what does it mean?
The problem is that you haven't defined the h prefix anywhere in your file. If you follow a JSF 2 tutorial, you will note this in the <html> tag definition (this one is taken from StackOverflow JSF wiki):
<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">
Where
h for JSF HTML tags like <h:head>, <h:body>, <h:inputText>, etc.
f is the prefix for JSF core like <f:view>, <f:selectItems>, <f:ajax>, etc.

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.

JSF prerenderview listener not executed on page forward?

What I'm going to describe can be the expected behaviour for people who know the JSF phase cycle well, but it is not obvious for me, so I ask for confirmation.
In a JSF page I put a listener for a prerenderview event.
The page is processed in consequence of a jsf-forward. The listener is not executed.
If I access the page directly through its url (perfroming a GET) the listener is executed.
Is there something wrong with my code or is this the right behaviour ?
I searched a lot on internet but didn't find anything useful.
Update
As I stated in the comments I jumped to wrong conclusion. What I described is not a general behaviour but a special case due to bugs or a more complex scenario.
Update 2
After further investigation I came to this conclusion: the problem seems to be related to a wrong way to put the preRenderView listener in a page which uses templates. Unfortunately it works in some circumstances and not in others.
<?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: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.prime.com.tr/ui">
<f:metadata>
<f:event listener="#{permessitemporaneiController.preCreate}" type="preRenderView" />
</f:metadata>
<ui:composition template="/template.xhtml">
...
I should have created an insert area inside the template and put the tag inside a in the previous code.
The weird thing is that with the 'wrong' code the listener is correctly called with GET requests, but doesn't work with a jsf-forward. Why ??
Thanks
Filippo

Resources