KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > projectmanagement > presentation > employees > Administering


1 package projectmanagement.presentation.employees;
2
3 import projectmanagement.presentation.*;
4 import projectmanagement.spec.employee.*;
5 import com.lutris.appserver.server.httpPresentation.*;
6 import org.enhydra.xml.xmlc.XMLObject;
7
8 import org.w3c.dom.*;
9 import org.w3c.dom.html.*;
10
11 /**
12  * Shows a list of employees to administer.
13  *
14  * @author Sasa Bojanic
15  * @version 1.0
16  */

17 public class Administering extends BasePO {
18
19    /**
20     * Superclass method override. Returns 1.
21     */

22    protected int getRequiredAuthLevel() {
23       return 1;
24    }
25
26    /**
27     * Default event. Just show the page.
28     */

29    public XMLObject handleDefault()
30          throws HttpPresentationException {
31
32     
33     
34        AdministeringHTML page = new AdministeringHTML();
35
36       /*String errorMsg = this.getSessionData().getAndClearUserMessage();
37       if(null != errorMsg) {
38          page.setTextLblErrorText(errorMsg);
39       } else {
40          page.getElementLblErrorText().getParentNode().removeChild(page.getElementLblErrorText());
41       }*/

42
43      
44       try {
45       EmployeeManager employeeManager = EmployeeManagerFactory.getEmployeeManager("projectmanagement.business.employee.EmployeeManagerImpl");
46       Employee[] employees=employeeManager.getAllEmployees();
47
48
49  // fetches the table element from HTML document
50
HTMLTableElement table = page.getElementTblEmployees();
51
52          if (employees!=null) {
53             for (int i=0; i<employees.length; i++) {
54                // creating row in HTML table which describes table properties
55
HTMLTableRowElement htmlRE=createNewRow(page,employees[i]);
56                // appending row at the end of table
57
table.appendChild(htmlRE);
58     
59             }
60          }
61          
62       //Remove template selection row from table
63
table.removeChild(page.getElementTemplateRow());
64 /*
65  * Catch Null pointer exception ( we canot make a instances of classes from business layer when we run ProjectManagement_pres )
66  * We need to allow ProjectManagement_pres to be functional , response
67  * will be default HTML page
68  */

69       } catch(NullPointerException JavaDoc ex) {
70       } catch(Exception JavaDoc ex) {
71          this.writeDebugMsg("Error populating list of employees: " + ex);
72          throw new ProjectManagementPresentationException("Error getting list of employees: ", ex);
73       }
74
75   
76       // write out HTML
77
return page;
78    }
79
80    /**
81    * Creates the new row of HTML table element, based on given parameters.
82    */

83    private HTMLTableRowElement createNewRow(AdministeringHTML administeringHTML,
84          Employee employee) {
85
86       String JavaDoc employeeID="";
87
88       try {
89          employeeID=employee.getHandle();
90          administeringHTML.setTextTxtFirstName(employee.getFirstName());
91          administeringHTML.setTextTxtLastName(employee.getLastName());
92          administeringHTML.setTextTxtMobilePhone(employee.getMobilePhone());
93          administeringHTML.setTextTxtEmail(employee.getEmail());
94       } catch (Exception JavaDoc ex) {}
95
96       // image to get details on employee
97
HTMLImageElement detailsImg=administeringHTML.getElementImgDetails();
98       detailsImg.setName(employeeID);
99
100       // image to modify employee information
101
HTMLImageElement modifyImg=administeringHTML.getElementImgModify();
102       modifyImg.setName(employeeID);
103
104       // image to delete employee
105
HTMLImageElement deleteImg=administeringHTML.getElementImgDelete();
106       deleteImg.setName(employeeID);
107
108       HTMLTableRowElement row=(HTMLTableRowElement)administeringHTML.
109          getElementTemplateRow().cloneNode(true);
110
111       return row;
112    }
113
114 }
115
116
Popular Tags