I'm have obtained the following certifications to date:

  • Sun Certified Developer for Java Web Services 5
  • Sun Certified Specialist for NetBeans IDE
  • Sun Certified Solaris 10 System Administrator
  • Sun Certified Developer for Java 2 platform
  • Sun Certified Enterprise Architect for the Java Platform, Enterprise Edition 5
  • Sun Certified Programmer for Java 2 platform 1.4
  • Sun Certified Enterprise Architect for J2EE 1.4 Technology
  • IBM Certified SOA Solution Designer
  • IBM Certified Solution Designer – WebSphere MQ V5.3
  • IBM Certified Deployment Professional – WebSphere Studio Application Monitor V3.2
  • IBM Certified Application Developer – Rational Application Developer for WebSphere V6
  • IBM Certified Advanced System Administrator – WebSphere Application Server 5.0
  • IBM Certified System Administrator – WebSphere Application Server 5.0
Christopher has posted 2 posts at DZone. View Full User Profile

How to Create a Java EE 6 Application with JSF 2, EJB 3.1, JPA, and NetBeans IDE 6.8

  • submit to reddit

Creating the Customer Details Web Page

Now we will create the page where the details of the selected customer is displayed and can be updated.

  1. In the Projects window, right-click on the Web project, CustomerApp-war, and select "New > XHTML...", specify CustomerDetails as the File Name.

  2. In the code editor, drag the item, "JSF Form from Entity" from the palette and drop it in between the <body></body> tags of the newly generated file, CustomerDetails.xhtml:

  3. A dialog with the title, "JSF Form from Entity" appears; select "com.customerapp.entity.Customer" as the Entity Bean, and "customer.details" as the Managed Bean property and click OK:

    Note: The result of this are lines of code automatically generated to display the label and input field of all the attributes in the Customer object in a 2 column grid.

  4. To enable the navigation from the Listing page to the Details and vice versa, you need to edit the faces-config.xml with the PageFlow editor and connect the 2 pages as shown in the diagram below:

    Note: The strings LIST and DETAILS must match the return String of the list and showDetails methods in the CustomerMBean.

  5. To see the result, save and deploy the application, go to the Customer listing page at URL, http://localhost:8080/CustomerApp-war/CustomerList.jsf, and click on the Customer ID on the first row in the table:

    Again, this looks very raw, so let's try to spice it up a little and include the Update function as well.

  6. The Discount Codes is a fixed list in the database, so it makes sense to present it in the form of a dropdown list for user to select for Update. So we will bind the value of the of the Discount Codes dropdown list to a new property, customer.discountCodes in CustomerMBean which returns an array of SelectItem(Object value, String label):
    * Returns an array of SelectItem to be displayed in the DiscountCode
    * Dropdown list in the CustomerDetails page
    * @return
    public javax.faces.model.SelectItem[] getDiscountCodes()
    SelectItem[] options = null;
    List discountCodes = customerSessionBean.getDiscountCodes();
    if (discountCodes != null && discountCodes.size() > 0)
    int i = 0;
    options = new SelectItem[discountCodes.size()];
    for (DiscountCode dc : discountCodes)
    options[i++] = new SelectItem(dc.getDiscountCode(),
    dc.getDiscountCode() + " (" + dc.getRate() + "%)");
    return options;

    Note: the value of each SelectItem is the Discount Code of type Character, as such, the value to be bound to the Discount Code needs to be of type Character for the preselect to work when the details of a customer is being displayed. So we will need to create the getter and setter methods for a new property, discount in the Customer Entity class, which uses Character as the argument:

    //New getter and setter methods for discount in Customer.java

    public Character getDiscount()
    return this.discountCode.getDiscountCode();

    public void setDiscount(Character code)
    this.discountCode = new DiscountCode(code);

  7. Bind this new property, "customer.details.discount" to the value of the <h:selectOneMenu> of the Discount Code field in the CustomerDetails.xhtml:
        <h:selectOneMenu id="discountCode" value="#{customer.details.discount}">
    <f:selectItems value="#{customer.discountCodes}"/>

  8. Make the rest of the changes to the XHTML page with the help of the code completion feature of NetBeans IDE:

    • Add the Command buttons, for Update and Back.

    • Rearrange the rows and use a different background color for the panelGrid.

    • Add a PrimeFaces component at the end of the page, <p:messages>, which displays FacesMessage created in the Managed Bean, e.g., a success message upon a successful update:
      <html xmlns="http://www.w3.org/1999/xhtml"
      <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
      <title>Customer Details</title>
      <p:resources />
      <h2><h:outputText value="Customer Details"/></h2>
      <h:panelGrid columns="2" bgcolor="#eff5fa">
      <h:outputLabel value="Customer ID:"/>
      <h:inputText id="customerId" value="#{customer.details.customerId}" disabled="true"/>
      <h:outputLabel value="Customer Name:"/>
      <h:inputText id="customerName" value="#{customer.details.name}"/>
      <h:outputLabel value="Credit Limit:"/>
      <h:inputText id="creditLimit" value="#{customer.details.creditLimit}"/>
      <h:outputLabel value="Discount Code"/>
      <h:selectOneMenu id="discountCode" value="#{customer.details.discount}">
      <f:selectItems value="#{customer.discountCodes}"/>
      <h:outputLabel value="Email:"/>
      <h:inputText id="email" value="#{customer.details.email}"/>
      <h:outputLabel value="Phone:"/>
      <h:inputText id="phone" value="#{customer.details.phone}"/>
      <h:outputLabel value="Fax:"/>
      <h:inputText id="fax" value="#{customer.details.fax}"/>
      <h:outputLabel value="Address (Line 1):"/>
      <h:inputText id="address1" value="#{customer.details.addressline1}"/>
      <h:outputLabel value="Address (Line 2):"/>
      <h:inputText id="address2" value="#{customer.details.addressline2}"/>
      <h:outputLabel value="State:"/>
      <h:inputText id="state" value="#{customer.details.state}"/>
      <h:outputLabel value="City:"/>
      <h:inputText id="city" value="#{customer.details.city}"/>
      <h:outputLabel value="Zip:"/>
      <h:inputText id="zip" value="#{customer.details.zip}"/>
      <h:commandButton id="back" value="Back" action="#{customer.list}"/>
      <h:commandButton id="update" value="Update" action="#{customer.update}"/>
      <p:messages showDetail="true" />
  9. Modify the update method of the CustomerMBean class to create a FacesMessage upon a successful update to demonstrate the use of the PrimeFaces <p:messages> component:
        public String update()
    customer = customerSessionBean.update(customer);
    FacesContext context = FacesContext.getCurrentInstance();
    context.addMessage(null, new FacesMessage(FacesMessage.SEVERITY_INFO,
    "Sucessful", "Record successfully saved!"));
    return "SAVED";
    The result of the changes should look like this after clicking on the Update button:

    Note: after performing the Update function, you should see something similar to the following in the log file, server.log:

    [#|2009-11-30T14:42:50.550+0800|INFO|glassfishv3.0|...|_ThreadID=28;_ThreadName=Thread-1;|Customer updated in
    [#|2009-11-30T14:42:50.950+0800|INFO|glassfishv3.0|...|_ThreadID=20;_ThreadName=Thread-1;|Customer with the
    following details has been updated:|#]
    [#|2009-11-30T14:42:50.950+0800|INFO|glassfishv3.0|...|_ThreadID=20;_ThreadName=Thread-1;|Customer ID=1,
    Name=JumboCom 2, Email=jumbocom@gmail.com|#]

    Note: The statement "Customer updated in CustomerSessionBean" although printed in the Session Bean (ThreadID=28) after invoking the send JMS message, appears before the next two lines which are printed in the Message-Driven Bean in ThreadID=20.


Published at DZone with permission of its author, Christopher Lam.

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)


Prashanth Kumar replied on Sat, 2010/05/22 - 10:21am

I am sort of stuck. When try to load the webpage, i only get the table header. No table data. I have not yet started to apply the primeface. It sort of looks like the Managed bean is not getting called. One question, when we drap and drop the JSF data table from entity , the pop up dialog has the cutomer entity bean in the list how the Managed bean property is empty. I had to type in customer.customers . Is that normal or should the IDE able to load the data based on entity bean.

Prashanth Kumar replied on Wed, 2010/06/02 - 11:11am in response to: Prashanth Kumar

Sorry, I figured out my mistake as to why the JSF table was not loading data. I had a extra space after the ManagedBean name anotation. Now I am able to see the JSF table with the pagination. However as i am using JSF2.0 , i have to figure out how to navigate from listing page to details page

Thang Pham replied on Thu, 2010/06/03 - 9:08am

I could not deploy the CustomerApp-war, so I create my own version of your application and try to deploy CustomerApp-war every time I add a new component. I figure out that the problem is when I add NotificationBean (Message Driven Bean). Particularly with the annotation @MessageDriven

@MessageDriven(mappedName = "jms/NotificationQueue", activationConfig = { @ActivationConfigProperty(propertyName = "acknowledgeMode", propertyValue = "Auto-acknowledge"), @ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Queue") })

Any Idea why? If I remove the annotation above, it deploy just fine. The server log show the Exception: "Message Driven Bean can't be Managed Bean". How can I fix this?

Thang Pham replied on Thu, 2010/06/03 - 10:40am in response to: Thang Pham

This is a bug in glassfish v3.0.0. Download glassfish v.3.0.1 for the fix

Thang Pham replied on Thu, 2010/06/03 - 10:47am

Hi I am bit confused about the NotificationBean (Message Driven Bean). So in your SessionBean, you merge a give "customer" into the persistent state then you send that object to the NotificationQueue. Here is where I got confused. Why and who do you try to send notification to? Where does "customer" object go after it get in the queue? When will the method onMessage(Message message) got invoke? Sorry I am a bit new to JPA.

Thang Pham replied on Thu, 2010/06/03 - 11:20am in response to: Henk De Boer

Do you have a tutorial some what like this but implemented correctly i like you mention above?

Naresh Amma replied on Tue, 2010/09/21 - 6:58am

just to get in to this account nothin to say k?

Naresh Amma replied on Tue, 2010/09/21 - 7:11am in response to: Rudy Hadoux


Musa Musa L replied on Tue, 2010/09/28 - 1:34pm

Hello, I was following your netbeans JavaEE 6 tutorial @ http://wiki.netbeans.org/DevelopJavaEE6App and i got stuck at this place 
<!-- Replace outputText with commandLink here to navigate 
                    to the details page -->
                    <h:commandLink action="#{customer.showDetails(item)}"
the server is having problems with the showDetails(item) call, since EL can only call managed bean properties with getters and setters
How do i solve this? Thanks. 
I used a f:setPropertyActionListener tag to set the current customer object to the selected item. it's all good

Suraj Chhetry replied on Thu, 2010/10/21 - 12:32am

Hi Christopher, Can you tell me know can i caught exception on manage bean that is thrown by EJB bean ?

Suraj Chhetry replied on Thu, 2010/10/21 - 12:52am

I got it Iam extending my exception class from RuntimeException so it is not coming to manage bean but when i extends from Exception it is working.

Vasko Gjurovski replied on Wed, 2010/11/17 - 10:53am

I am having problem with the navigation rules. I did everything as been told above in the tutorial, however tho links to the detail pages do not do anything. I even putted a System.out.println in the showDetails method, but nothing is printed out. Any idea what might be causing this?

Gökhan Ozar replied on Thu, 2010/11/25 - 4:01pm

Hi, Thanks for the great tutorial which I really admire. I have gone through the tutorial with PrimeFaces 2.1 which is the latest stable release as of this writing, and my CustomerList.xhtml has a slightly different output on http://localhost:8080/CustomerApp-war/CustomerList.jsf with no pagination or column sorting options. I took it that it should be automatic from what I see in the output in your tutorial. So is it the version difference of PrimeFaces? BTW, the zip file of the completed app on the summary page is still corrupt or incomplete, so I can't compare. Please consider re-uploading it.

Cassio Seffrin replied on Mon, 2011/01/24 - 12:30pm

Hi Christopher,

First: congratulations you made a great job. wonderfull tutorial.

Second:  following your tuto the application work fine for me. To complete the CRUD, lack only do the add page. I think this is simple, but I'm not so familiar to JSF. You have a sample code for this application?

The persist method in the EJB it's done, lack only create a request (buttom create) and change something in CustomerDetails.jsf, but if you have a sample will be appreciated?

Best Regard,


Soumaya Touati replied on Wed, 2011/07/13 - 1:29pm in response to: Christopher Lam

HI Christopher thank you for the tutorial "How to Create a Java EE 6 Application with JSF 2, EJB 3.1, JPA, and NetBeans IDE 6.8" it was very helpful for me. please i need your help to create a new customer its very urgent please help me i need it to accomplish my work .

Sameera Samarasinghe replied on Thu, 2011/07/28 - 6:13am

Hi, When I try to create the template for XHTML I got "No library found for this namespace" error for the followings xmlns:f="http://java.sun.com/jsf/core" xmlns:h="http://java.sun.com/jsf/html" xmlns:p="http://primefaces.prime.com.tr/ui" please help me with this. Thanks :) Sameera

Sameera Samarasinghe replied on Thu, 2011/07/28 - 7:22am

once the DOCTYPE statement removed there's no error.
Please help me

Navpreet Singh replied on Thu, 2011/08/18 - 6:35pm

Hi Christopher,

Thanks for the great tutorial. It works and I learned a lot along the way. 

But when I start following your next tutorial


At the end when I go to CustomerList.jsp in browser and click on first record it opens up CustomerDetails.jsp without redirecting me to Login.jsp.
I even copied your solution still it goes to CustomerDetails.jsp without login. Can you please help me with this?



Raul Lapitzondo replied on Fri, 2011/11/11 - 9:36am in response to: Christopher Lam

Thank's for this tutorial is a great job.

I need understand the first part, about how to create "jms/NotificationQueue" in glassfish server. Can you explain this ?.

Thank's in advance

James Jithin replied on Tue, 2012/01/31 - 2:15am

Great tutorial. Screen-shots are good to follow. Also, makes us work a little to achieve the goal. :) Good work.

Manish Chowdhary replied on Thu, 2012/03/22 - 8:10pm

Do you have an updated blog post for this? GoECart

Matt Coleman replied on Mon, 2013/04/01 - 3:55am in response to: Cagatay Civici

thanks for this information Cagatay

buffalo freelance web designer 

Isaac Mashoboko replied on Wed, 2013/10/09 - 12:47pm

Thank for the great tutorial. This tutorial is all about updating and retrieving customers. I'd like to ask how can i include customer registration code in the project. sorry for my bad english.

thank you

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.