I'm developing a JSF web application with PrimeFaces 3.5 on Eclipse 4.3. There are no compiletime or runtime errors and the application deploys successfully. However, I cannot get the desired output in browser. The PrimeFaces components do not show up, while the standard JSF components do.
I'm not sure if I configured everything right. The PrimeFaces JAR is at least inside /WEB-INF/lib
:
And the PrimeFaces XML namespace is declared as xmlns:p="http:\\primefaces.org\ui"
And I mapped the FacesServlet
on *.xhtml
:
Here's the full source code of 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:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:p=" http://primefaces.org/ui" >
<h:body>
<h:head ><title>Login Page !!</title></h:head>
<h:form>
<p:panel id="panel" header="Login Panel" style="margin-bottom:10px;">
<h:panelGrid columns="3">
<h:outputLabel value="User Id:" />
<p:inputText id="id" value="loginBean.id" required="true" requiredMessage="ID required"/>
<p:message for="id" />
<p:outputLabel value="User Name:" />
<p:inputText id="name" value="loginBean.name" required="true" requiredMessage="Name required" />
<p:message for="name" />
</h:panelGrid>
</p:panel>
<p:commandButton type="Submit" value="Submit" action="#" style="margin-right:20px;" />
`
The output looks like this:
As you see, <h:outputText>
did its job, but none of <p:xxx>
show up. How is this caused and how can I solve it?
As to the cause of your concrete problem of PrimeFaces components not being rendered, as per the screenshot, you have a leading blank space in PrimeFaces taglib URI:
xmlns:p=" http://primefaces.org/ui"
This is significant and thus wrong. Get rid of it:
xmlns:p="http://primefaces.org/ui"
This way the PrimeFaces components must be parsed and appear in the HTML output.
For the remainder I strongly recommend you to go through a sane JSF2 tutorial first. You're making several conceptual mistakes which are already covered by a decent Hello World example. Start at our JSF wiki page. Those mistakes do however not have this "blank page" as consequence. They will cause different problems (e.g. CSS/JS not functioning and form submit not working). If you still stucks on that, you should essentially be asking a new question.
This is not directly answer on this question, but it's related to it. I want to share my experience with the problem "PrimeFaces tags not rendering". I am developing JSF 2.2 app on WildFly, and here is my index.xhtml:
<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">
<h:body>
<h:form>
<p:editor value="#{mDb.newMessage.content}"></p:editor>
</h:form>
</h:body>
</html>
When an app is running, the editor doesn't appear, and this was very strange to me, because PrimeFaces was configured correctly in project.
I accidentally discovered cause of problem. There was not a h:head
tag in index.xhtml. When I put head tag, PrimeFaces components rendered successfully!!
I hope this could help someone.
1.
When ever you are referring to Managed Bean properties from JSF components, use correct syntax for JSF EL statements.
#{bean_name.property}
In your code you are forgetting to provide #{}
.
For example at line #15 in login.xhtml use :
<h:inputText id="id" value="#{loginBean.id}" required="true" requiredMessage="ID required"/>
2.
You are keeping <h:head>
inside <h:body>
. Its not a good practice.
Keep <h:head>
out side <h:body>
.
Actual structure would be:
<!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">
<h:head>
<title></title>
<h:head>
<h:body>
<!-- Your Code -->
</h:body>
</html>
3.
You may be getting exception in ManagedBean LoginBean.java class.
Please post the code instead of screenshots.
if you build your proeject mit maven remember to include a dependency of primefaces lib into pom.xml
best regards