Search code examples
eclipsejsfjsf-2primefaces

PrimeFaces components are not rendered in browser in spite of dependency being present


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:

enter image description here

And the PrimeFaces XML namespace is declared as xmlns:p="http:\\primefaces.org\ui"

enter image description here

And I mapped the FacesServlet on *.xhtml:

enter image description here

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:

enter image description here

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?


Solution

  • 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.