Using PrimeFaces with Codenvy

PrimeFaces is an open source component library for JavaServer Faces, developed by Prime Teknoloji. It provides a collection of mostly visual components (widgets). These can be used by JSF programmers in addition to the small set of basic components that ship with the core JSF platform to compose the UI for a web application. Here we demonstrate CommandButton functionality of PrimeFaces.

Create a Project

Login to your Codenvy workspace and create a New WAR Project say “CommandButtonPrimeFaces”. Project file structure is shown below :

Pom.xml and dependencies

Specify the below dependencies in pom.xml which are prerequisite for the HTTPClient implementation. Make sure these jars are included under Maven Dependencies.

  • primefaces.jar
  • jsf-api.jar
  • jsf-impl.jar
  • jstl.jar
  • servlet-api.jar
  • jsp-api.jar
  • el-impl.jar

Dependencies in pom.xml:


<!-- PrimeFaces -->

<!-- JSF 2 -->




<!-- EL -->


Create NameBean Class

This will be our ManagedBean for our form when user submits the form, this bean is populated and respective function is executed.

@ManagedBean(name = "pprBean")
public class NameBean {
        private String inputname;
       public String getInputname() {
                return inputname;
        public void setInputname(String inpName) {
                this.inputname = inpName;
        public void saveName(ActionEvent actionEvent) {
                FacesContext.getCurrentInstance().addMessage(null, new FacesMessage("Welcome " + inputname + " !"));

Create commandButton.xhtml

commandButton.xhtml shows us the form and when user submits the form, respective ManagedBean is populated and function is invoked.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
<html xmlns=""
	<h2>PrimeFaces Codenvy</h2>
         <h:form id="form">
            <p:panel id="panel" header="Name" style="margin-bottom:10px;">
                <p:messages id="messages" />
                <h:panelGrid columns="3">
                    <h:outputLabel for="inputname" value="Name: *" />
                    <p:inputText id="inputname"
                        value="#{pprBean.inputname}" required="true" label="Name">
                        <f:validateLength minimum="2" />
                    <p:message for="inputname" />
            <p:commandButton value="Submit" update="panel,display" id="ajax"
 actionListener="#{pprBean.saveName}" styleClass="ui-priority-primary"/>
            <p:panel id="display" header="Information" style="margin-top:10px;">
                <h:panelGrid columns="2">
                    <h:outputText value="Name: " />
                    <h:outputText value="#{pprBean.inputname}" />

Create web.xml

We are mapping the all requests for resources .jsf,.faces,.xhtml(url pattern) to be handled by Faces Servlet.

"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"" >

<display-name>PrimeFaces Web Application</display-name>


<!-- Welcome page -->

<!-- JSF mapping -->
<servlet-name>Faces Servlet</servlet-name>

<!-- Map these files with JSF -->
<servlet-name>Faces Servlet</servlet-name>
<servlet-name>Faces Servlet</servlet-name>
<servlet-name>Faces Servlet</servlet-name>
<servlet-name>Faces Servlet</servlet-name>

Build and Run the Application

Upon successful building the application and executing, it loads commandButton.xhtml where we input a NAME, then it will be successfully submit and shows what has been submitted back to user without page refresh.