Step 2: Adding a listDepartments() Method to the Session Bean

Previous topic
Previous
Next topic
Next

Now you need to call the findByDname() method on the entity bean by creating a new method on the session bean.

To add a new method to the session bean:

  1. In the UML diagram, add a new method to the session bean by clicking below the listDepartments() method and typing the following:
    listByDname(String dname) : String
  2. In the Navigator, double-click hrAppBean.java to open it in the Code Editor.
  3. In the Structure pane, double-click listByDname() to jump to that method in the code.
  4. Replace the stub method with the following code:
public String listByDname(String dname)
  {
    try {
     DeptLocal dept = getDeptLocalHome().findByDname(dname) ;

     StringBuffer sb = new StringBuffer ("Department Details....\n");
     sb.append(dept.getDepartment_id()  + "......" + 
     dept.getDepartment_name() + "......" + 
     dept.getLocation_id()  + "......\n");
     return sb.toString();
     }
     catch(NamingException ne)
     {
     System.out.println(ne.toString());
     throw new javax.ejb.EJBException(ne);
     }
     catch(FinderException fe)
     {
     System.out.println(fe.toString());
     throw new javax.ejb.EJBException(fe);
     }
  }