Netbeans + Visual Paradigm = EJB Tutorial (Part 2)

In part 1 of this tutorial we walk through the modeling and code creation of an EJB using Netbeans and Visual Paradigm. In part 2 we will create a simple sample ZK web application that reads data using the EJB.


  • The project from completed tutorial part 1


  • Create web application ‘demoejbweb’

    Create web application

    Create web application

  • Add the EJB from dem demoejb.jar
    Note: We have 2 independent projects now, if you rebuild the ejb, you also need to rebuild the web application.

    Add library

  • Add a listbox to the zul file
    <?xml version="1.0" encoding="UTF-8"?>
    <zk xmlns="">
        <window id="list" apply="controller.indexController" title="List">
            <listbox id="lstCustomer" width="100%" >
                <listhead sizable="true">
                    <listheader id="lblLast" label=""/>
                    <listheader id="lblFirst" label="" />
                    <listheader id="lblDate" label="" />
  • Add the controller class

    Controller Class

    package controller;
    import demo.Customer_name;
    import facade.Customer_nameFacade;
    import java.util.List;
    import javax.naming.Context;
    import javax.naming.InitialContext;
    import org.zkoss.zk.ui.Component;
    import org.zkoss.zk.ui.util.GenericForwardComposer;
    import org.zkoss.zul.ListModelList;
    import org.zkoss.zul.Listbox;
    import org.zkoss.zul.Listcell;
    import org.zkoss.zul.Listitem;
    import org.zkoss.zul.ListitemRenderer;
    public class indexController extends GenericForwardComposer {
        private Listbox lstCustomer;
        Context context;
        Customer_nameFacade customer_nameFacade;
        List<Customer_name> customers = null;
        public void doAfterCompose(Component comp) throws Exception {
            context = new InitialContext();
            try {
                customer_nameFacade = (Customer_nameFacade) context.lookup("java:global/demoejbweb/Customer_nameFacade");
                customers = customer_nameFacade.findAll();
                lstCustomer.setModel(new ListModelList(customers));
            } catch (Exception ex) {
        private void setupRenderer() {
            ListitemRenderer listitem = new ListitemRenderer() {
                public void render(Listitem item, Object data) throws Exception {
                    item.appendChild(new Listcell(((Customer_name) data).getLast_name()));
                    item.appendChild(new Listcell(((Customer_name) data).getFirst_name()));
                    item.appendChild(new Listcell(((Customer_name) data).getEntrydate().toString()));
                    Listcell listcell = new Listcell();
  • Add some data using the “data explorer” in Netbeans
    Note: If you chosed the strategy ‘drop and create‘ for your persistence unit, the data will be lost on the next deployment. After the tables have been created change to ‘Nothing‘.

    Adding data

  • Run the web application

    Running web application


  • No, you don’t need to use the context to access the EJB, you could use the annotation approach, provided both Netbeans projects are part of one enterprise application.
  • In part 3 we will tinker with real databases, PostgreSQL and Oracle.

2 thoughts on “Netbeans + Visual Paradigm = EJB Tutorial (Part 2)

  1. Pingback: Netbeans + Visual Paradigm = EJB Tutorial (Part 3) « The JavaDude Weblog

  2. Pingback: Netbeans + Visual Paradigm = EJB Tutorial (Part 4) « The JavaDude Weblog

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s