Source Code Cross Referenced for Edit.java in  » J2EE » Enhydra-Demos » projectmanagement » presentation » employees » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » J2EE » Enhydra Demos » projectmanagement.presentation.employees 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package projectmanagement.presentation.employees;
002:
003:        import projectmanagement.*;
004:        import projectmanagement.presentation.*;
005:
006:        import projectmanagement.spec.employee.*;
007:        import projectmanagement.spec.*;
008:        import com.lutris.appserver.server.httpPresentation.*;
009:        import org.enhydra.xml.xmlc.XMLObject;
010:
011:        import org.w3c.dom.*;
012:        import org.w3c.dom.html.*;
013:
014:        import java.sql.Date;
015:        import java.util.*;
016:
017:        /**
018:         * Manages all actions on employees.
019:         *
020:         * @author Sasa Bojanic
021:         * @version 1.0
022:         */
023:        public class Edit extends BasePO {
024:
025:            /**
026:             * Constants
027:             */
028:            private static String FIRST_NAME = "txtFirstName";
029:            private static String LAST_NAME = "txtLastName";
030:            private static String LOGIN = "txtLogin";
031:            private static String PASSWORD = "txtPassword";
032:            private static String TITLE = "txtTitle";
033:            private static String TITLE_OF_COURTESY = "txtTitleOfCourtesy";
034:            private static String BIRTH_DATE_YYYY = "txtBirthDateYYYY";
035:            private static String BIRTH_DATE_MM = "txtBirthDateMM";
036:            private static String BIRTH_DATE_DD = "txtBirthDateDD";
037:            private static String HIRE_DATE_YYYY = "txtHireDateYYYY";
038:            private static String HIRE_DATE_MM = "txtHireDateMM";
039:            private static String HIRE_DATE_DD = "txtHireDateDD";
040:            private static String ADDRESS = "txtAddress";
041:            private static String CITY = "txtCity";
042:            private static String REGION = "txtRegion";
043:            private static String POSTAL_CODE = "txtPostalCode";
044:            private static String COUNTRY = "txtCountry";
045:            private static String HOME_PHONE = "txtHomePhone";
046:            private static String MOBILE_PHONE = "txtMobilePhone";
047:            private static String EMAIL = "txtEmail";
048:            private static String NOTES = "txtNotes";
049:            private static String IS_ADMIN = "cbxIsAdmin";
050:
051:            private static String EMPLOYEE_ID = "employeeID";
052:            private static String CONTEXT_PAGE = "Context.po";
053:            private static String ADD = "add";
054:            private static String DELETE = "delete";
055:            private static String MODIFY = "modify";
056:            private static String DETAILS = "showDetailsPage";
057:            private static String EVENT = "event";
058:
059:            /**
060:             * Superclass method override. Returns 1.
061:             */
062:            protected int getRequiredAuthLevel() {
063:                String event = "";
064:                try {
065:                    event = this .getComms().request.getParameter(EVENT);
066:                } catch (Exception ex) {
067:                }
068:
069:                if (event != null && event.equalsIgnoreCase(DETAILS)) {
070:                    return 1;
071:                } else {
072:                    return 2;
073:                }
074:            }
075:
076:            /**
077:             *  Default event. Just show the page for editing.
078:             */
079:            public XMLObject handleDefault() throws HttpPresentationException {
080:                return showModifyPage(null, false);
081:            }
082:
083:            /**
084:             * handle show add employee page event.
085:             *
086:             * @return html document
087:             * @exception HttpPresentationException
088:             */
089:            public XMLObject handleShowAddPage()
090:                    throws HttpPresentationException {
091:                return showAddPage(null);
092:            }
093:
094:            /**
095:             * handle show details employee page event.
096:             *
097:             * @return html document
098:             * @exception HttpPresentationException
099:             */
100:            public XMLObject handleShowDetailsPage()
101:                    throws HttpPresentationException {
102:                return showModifyPage(null, true);
103:            }
104:
105:            /*
106:             * Modifies an existing employee
107:             *
108:             * @return html document
109:             * @exception HttpPresentationException
110:             */
111:            public XMLObject handleModify() throws HttpPresentationException {
112:                String employeeID = this .getComms().request
113:                        .getParameter(EMPLOYEE_ID);
114:                Employee employee = null;
115:
116:                // Try to get the employee by its ID
117:                try {
118:
119:                    EmployeeManager employeeManager = EmployeeManagerFactory
120:                            .getEmployeeManager("projectmanagement.business.employee.EmployeeManagerImpl");
121:                    employee = employeeManager.findEmployeeByID(employeeID);
122:
123:                } catch (Exception ex) {
124:                    this .getSessionData().setUserMessage(
125:                            "Please choose a valid employee to edit");
126:                    throw new ClientPageRedirectException(CONTEXT_PAGE);
127:                }
128:
129:                try {
130:                    // check if the username already exists
131:                    if (!isExistingLogin(employee)) {
132:                        saveEmployee(employee);
133:                        throw new ClientPageRedirectException(CONTEXT_PAGE);
134:                    } else {
135:                        return showModifyPage(
136:                                "The login you've entered already exists !",
137:                                false);
138:                    }
139:                } catch (Exception ex) {
140:                    return showModifyPage(
141:                            "To modify this employee, you must fill out fields properly!",
142:                            false);
143:                }
144:            }
145:
146:            /*
147:             * Adds a employee to the employee database
148:             *
149:             * @return html document
150:             * @exception HttpPresentationException
151:             */
152:            public XMLObject handleAdd() throws HttpPresentationException {
153:                try {
154:
155:                    EmployeeManager employeeManager = EmployeeManagerFactory
156:                            .getEmployeeManager("projectmanagement.business.employee.EmployeeManagerImpl");
157:                    Employee employee = employeeManager.getEmployee();
158:
159:                    // check if the username already exists
160:                    if (!isExistingLogin(employee)) {
161:                        saveEmployee(employee);
162:                        throw new ClientPageRedirectException(CONTEXT_PAGE);
163:                    } else {
164:                        return showAddPage("The login you've entered already exists !");
165:                    }
166:                    /*
167:                     * Catch Null pointer exception ( we canot make a instances of classes from business layer  when we run ProjectManagement_pres )
168:                     * We need  to allow ProjectManagement_pres to be functional ,  response
169:                     * will be default HTML page 
170:                     */
171:                } catch (NullPointerException ex) {
172:                    return showAddPage("You cannot add employee while runing ProjectManagement_pres");
173:                } catch (Exception ex) {
174:                    return showAddPage("To add this employee, you must fill out fields properly!");
175:                }
176:            }
177:
178:            /*
179:             * Deletes a Employee from the Employee database
180:             *
181:             * @return html document
182:             * @exception HttpPresentationException
183:             */
184:            public XMLObject handleDelete() throws HttpPresentationException,
185:                    ProjectManagementPresentationException {
186:                String employeeID = this .getComms().request
187:                        .getParameter(EMPLOYEE_ID);
188:
189:                try {
190:
191:                    EmployeeManager employeeManager = EmployeeManagerFactory
192:                            .getEmployeeManager("projectmanagement.business.employee.EmployeeManagerImpl");
193:                    Employee employee = employeeManager
194:                            .findEmployeeByID(employeeID);
195:
196:                    String fullName = employee.getFirstName() + " "
197:                            + employee.getLastName();
198:                    employee.delete();
199:                    this .getSessionData().setUserMessage(
200:                            "The employee, " + fullName + ", was deleted");
201:                    // Catch any possible database exception as well as the null pointer
202:                    //  exception if the employee is not found and is null after findEmployeeByID
203:                } catch (Exception ex) {
204:                    this .getSessionData().setUserMessage(
205:                            "Please choose a valid employee to delete");
206:                }
207:                // Redirect to the catalog page which will display the error message,
208:                //  if there was one set by the above exception
209:                throw new ClientPageRedirectException(CONTEXT_PAGE);
210:            }
211:
212:            /**
213:             * Produce HTML for this PO, populated by the employee information
214:             * that the user wants to edit
215:             *
216:             * @param errorMsg, the error messages
217:             * @param disabled, if controls are disabled
218:             * @return html document
219:             * @exception HttpPresentationException
220:             */
221:            public XMLObject showModifyPage(String errorMsg, boolean disabled)
222:                    throws HttpPresentationException,
223:                    ProjectManagementPresentationException {
224:
225:                String firstName = this .getComms().request
226:                        .getParameter(FIRST_NAME);
227:                String lastName = this .getComms().request
228:                        .getParameter(LAST_NAME);
229:                String login = this .getComms().request.getParameter(LOGIN);
230:                String password = this .getComms().request
231:                        .getParameter(PASSWORD);
232:                String title = this .getComms().request.getParameter(TITLE);
233:                String titleOfCourtesy = this .getComms().request
234:                        .getParameter(TITLE_OF_COURTESY);
235:                String birthDateYYYY = this .getComms().request
236:                        .getParameter(BIRTH_DATE_YYYY);
237:                String birthDateMM = this .getComms().request
238:                        .getParameter(BIRTH_DATE_MM);
239:                String birthDateDD = this .getComms().request
240:                        .getParameter(BIRTH_DATE_DD);
241:                String hireDateYYYY = this .getComms().request
242:                        .getParameter(HIRE_DATE_YYYY);
243:                String hireDateMM = this .getComms().request
244:                        .getParameter(HIRE_DATE_MM);
245:                String hireDateDD = this .getComms().request
246:                        .getParameter(HIRE_DATE_DD);
247:                String address = this .getComms().request.getParameter(ADDRESS);
248:                String city = this .getComms().request.getParameter(CITY);
249:                String region = this .getComms().request.getParameter(REGION);
250:                String postalCode = this .getComms().request
251:                        .getParameter(POSTAL_CODE);
252:                String country = this .getComms().request.getParameter(COUNTRY);
253:                String homePhone = this .getComms().request
254:                        .getParameter(HOME_PHONE);
255:                String mobilePhone = this .getComms().request
256:                        .getParameter(MOBILE_PHONE);
257:                String email = this .getComms().request.getParameter(EMAIL);
258:                String notes = this .getComms().request.getParameter(NOTES);
259:                String isAdmin = this .getComms().request.getParameter(IS_ADMIN);
260:
261:                String employeeID = this .getComms().request
262:                        .getParameter(EMPLOYEE_ID);
263:                // Instantiate the page object
264:                EditHTML page = new EditHTML();
265:
266:                Employee employee = null;
267:
268:                try {
269:
270:                    EmployeeManager employeeManager = EmployeeManagerFactory
271:                            .getEmployeeManager("projectmanagement.business.employee.EmployeeManagerImpl");
272:                    employee = employeeManager.findEmployeeByID(employeeID);
273:
274:                    /*
275:                     * Catch Null pointer exception ( we canot make a instances of classes from business layer  when we run ProjectManagement_pres )
276:                     * We need  to allow ProjectManagement_pres to be functional ,  response
277:                     * will be default HTML page with message
278:                     */
279:                } catch (NullPointerException ex) {
280:                    page.setTextErrorText("This is a default HTML page");
281:                    return page;
282:                    // Catch any possible database exception in findEmployeeByID()
283:                } catch (ProjectManagementException ex) {
284:                    this .getSessionData().setUserMessage(
285:                            "Please choose a valid employee to edit");
286:                    throw new ClientPageRedirectException(CONTEXT_PAGE);
287:                }
288:
289:                try {
290:                    // If we received a valid employeeID then try to show the employee's contents,
291:                    // otherwise try to use the HTML input parameters
292:                    page.getElementEmployeeID().setValue(employee.getHandle());
293:
294:                    HTMLInputElement el = page.getElementTxtFirstName();
295:                    el.setDisabled(disabled);
296:                    if (null != firstName && firstName.length() != 0) {
297:                        el.setValue(firstName);
298:                    } else {
299:                        el.setValue(employee.getFirstName());
300:                    }
301:
302:                    el = page.getElementTxtLastName();
303:                    el.setDisabled(disabled);
304:                    if (null != lastName && lastName.length() != 0) {
305:                        el.setValue(lastName);
306:                    } else {
307:                        el.setValue(employee.getLastName());
308:                    }
309:
310:                    el = page.getElementTxtLogin();
311:                    el.setDisabled(disabled);
312:                    if (!disabled) {
313:                        if (null != login && login.length() != 0) {
314:                            el.setValue(login);
315:                        } else {
316:                            el.setValue(employee.getLogin());
317:                        }
318:                    } else {
319:                        el
320:                                .getParentNode()
321:                                .getParentNode()
322:                                .getParentNode()
323:                                .removeChild(el.getParentNode().getParentNode());
324:                    }
325:
326:                    el = page.getElementTxtPassword();
327:                    el.setDisabled(disabled);
328:                    if (!disabled) {
329:                        if (null != password && password.length() != 0) {
330:                            el.setValue(password);
331:                        } else {
332:                            el.setValue(employee.getPassword());
333:                        }
334:                    } else {
335:                        el
336:                                .getParentNode()
337:                                .getParentNode()
338:                                .getParentNode()
339:                                .removeChild(el.getParentNode().getParentNode());
340:                    }
341:
342:                    el = page.getElementTxtTitle();
343:                    el.setDisabled(disabled);
344:                    if (null != title && title.length() != 0) {
345:                        el.setValue(title);
346:                    } else {
347:                        el.setValue(employee.getTitle());
348:                    }
349:
350:                    el = page.getElementTxtTitleOfCourtesy();
351:                    el.setDisabled(disabled);
352:                    if (null != titleOfCourtesy
353:                            && titleOfCourtesy.length() != 0) {
354:                        el.setValue(titleOfCourtesy);
355:                    } else {
356:                        el.setValue(employee.getTitleOfCourtesy());
357:                    }
358:
359:                    el = page.getElementTxtBirthDateYYYY();
360:                    el.setDisabled(disabled);
361:                    if (null != birthDateYYYY && birthDateYYYY.length() != 0) {
362:                        el.setValue(birthDateYYYY);
363:                    } else {
364:                        Calendar cal = new GregorianCalendar();
365:                        cal.setTime(employee.getBirthDate());
366:                        el.setValue(String.valueOf(cal.get(Calendar.YEAR)));
367:                    }
368:
369:                    el = page.getElementTxtBirthDateMM();
370:                    el.setDisabled(disabled);
371:                    if (null != birthDateMM && birthDateMM.length() != 0) {
372:                        el.setValue(birthDateMM);
373:                    } else {
374:                        Calendar cal = new GregorianCalendar();
375:                        cal.setTime(employee.getBirthDate());
376:                        el
377:                                .setValue(String.valueOf(cal
378:                                        .get(Calendar.MONTH) + 1));
379:                    }
380:
381:                    el = page.getElementTxtBirthDateDD();
382:                    el.setDisabled(disabled);
383:                    if (null != birthDateDD && birthDateDD.length() != 0) {
384:                        el.setValue(birthDateDD);
385:                    } else {
386:                        Calendar cal = new GregorianCalendar();
387:                        cal.setTime(employee.getBirthDate());
388:                        el.setValue(String.valueOf(cal
389:                                .get(Calendar.DAY_OF_MONTH)));
390:                    }
391:
392:                    el = page.getElementTxtHireDateYYYY();
393:                    el.setDisabled(disabled);
394:                    if (null != hireDateYYYY && hireDateYYYY.length() != 0) {
395:                        el.setValue(hireDateYYYY);
396:                    } else {
397:                        Calendar cal = new GregorianCalendar();
398:                        cal.setTime(employee.getHireDate());
399:                        el.setValue(String.valueOf(cal.get(Calendar.YEAR)));
400:                    }
401:
402:                    el = page.getElementTxtHireDateMM();
403:                    el.setDisabled(disabled);
404:                    if (null != hireDateMM && hireDateMM.length() != 0) {
405:                        el.setValue(hireDateMM);
406:                    } else {
407:                        Calendar cal = new GregorianCalendar();
408:                        cal.setTime(employee.getHireDate());
409:                        el
410:                                .setValue(String.valueOf(cal
411:                                        .get(Calendar.MONTH) + 1));
412:                    }
413:
414:                    el = page.getElementTxtHireDateDD();
415:                    el.setDisabled(disabled);
416:                    if (null != hireDateDD && hireDateDD.length() != 0) {
417:                        el.setValue(hireDateDD);
418:                    } else {
419:                        Calendar cal = new GregorianCalendar();
420:                        cal.setTime(employee.getHireDate());
421:                        el.setValue(String.valueOf(cal
422:                                .get(Calendar.DAY_OF_MONTH)));
423:                    }
424:
425:                    el = page.getElementTxtAddress();
426:                    el.setDisabled(disabled);
427:                    if (null != address && address.length() != 0) {
428:                        el.setValue(address);
429:                    } else {
430:                        el.setValue(employee.getAddress());
431:                    }
432:
433:                    el = page.getElementTxtCity();
434:                    el.setDisabled(disabled);
435:                    if (null != city && city.length() != 0) {
436:                        el.setValue(city);
437:                    } else {
438:                        el.setValue(employee.getCity());
439:                    }
440:
441:                    el = page.getElementTxtRegion();
442:                    el.setDisabled(disabled);
443:                    if (null != region && region.length() != 0) {
444:                        el.setValue(region);
445:                    } else {
446:                        el.setValue(employee.getRegion());
447:                    }
448:
449:                    el = page.getElementTxtPostalCode();
450:                    el.setDisabled(disabled);
451:                    if (null != postalCode && postalCode.length() != 0) {
452:                        el.setValue(postalCode);
453:                    } else {
454:                        el.setValue(employee.getPostalCode());
455:                    }
456:
457:                    el = page.getElementTxtCountry();
458:                    el.setDisabled(disabled);
459:                    if (null != country && country.length() != 0) {
460:                        el.setValue(country);
461:                    } else {
462:                        el.setValue(employee.getCountry());
463:                    }
464:
465:                    el = page.getElementTxtHomePhone();
466:                    el.setDisabled(disabled);
467:                    if (null != homePhone && homePhone.length() != 0) {
468:                        el.setValue(homePhone);
469:                    } else {
470:                        el.setValue(employee.getHomePhone());
471:                    }
472:
473:                    el = page.getElementTxtMobilePhone();
474:                    el.setDisabled(disabled);
475:                    if (null != mobilePhone && mobilePhone.length() != 0) {
476:                        el.setValue(mobilePhone);
477:                    } else {
478:                        el.setValue(employee.getMobilePhone());
479:                    }
480:
481:                    el = page.getElementTxtEmail();
482:                    el.setDisabled(disabled);
483:                    if (null != email && email.length() != 0) {
484:                        el.setValue(email);
485:                    } else {
486:                        el.setValue(employee.getEmail());
487:                    }
488:
489:                    //HTMLTextAreaElement tael=page.getElementTxtNotes();
490:                    el = page.getElementTxtNotes();
491:                    el.setDisabled(disabled);
492:                    if (null != notes && notes.length() != 0) {
493:                        el.setValue(notes);
494:                    } else {
495:                        el.setValue(employee.getNotes());
496:                    }
497:
498:                    el = page.getElementCbxIsAdmin();
499:                    el.setDisabled(disabled);
500:                    if (null != isAdmin) {
501:                        el.setChecked(true);
502:                    } else {
503:                        el.setChecked(false);
504:                    }
505:
506:                    el = page.getElementBtnSave();
507:                    el.setDisabled(disabled);
508:
509:                    if (null == errorMsg) {
510:                        page.getElementErrorText().getParentNode().removeChild(
511:                                page.getElementErrorText());
512:                    } else {
513:                        page.setTextErrorText(errorMsg);
514:                    }
515:                } catch (ProjectManagementException ex) {
516:                    throw new ProjectManagementPresentationException(
517:                            "Error populating page for employee editing", ex);
518:                }
519:
520:                page.getElementEvent().setValue(MODIFY);
521:                return page;
522:            }
523:
524:            /**
525:             * Produce HTML for this PO
526:             *
527:             * @param errorMsg, the error messages
528:             * @return html document
529:             * @exception HttpPresentationException
530:             */
531:            public XMLObject showAddPage(String errorMsg)
532:                    throws HttpPresentationException,
533:                    ProjectManagementPresentationException {
534:
535:                String firstName = this .getComms().request
536:                        .getParameter(FIRST_NAME);
537:                String lastName = this .getComms().request
538:                        .getParameter(LAST_NAME);
539:                String login = this .getComms().request.getParameter(LOGIN);
540:                String password = this .getComms().request
541:                        .getParameter(PASSWORD);
542:                String title = this .getComms().request.getParameter(TITLE);
543:                String titleOfCourtesy = this .getComms().request
544:                        .getParameter(TITLE_OF_COURTESY);
545:                String birthDateYYYY = this .getComms().request
546:                        .getParameter(BIRTH_DATE_YYYY);
547:                String birthDateMM = this .getComms().request
548:                        .getParameter(BIRTH_DATE_MM);
549:                String birthDateDD = this .getComms().request
550:                        .getParameter(BIRTH_DATE_DD);
551:                String hireDateYYYY = this .getComms().request
552:                        .getParameter(HIRE_DATE_YYYY);
553:                String hireDateMM = this .getComms().request
554:                        .getParameter(HIRE_DATE_MM);
555:                String hireDateDD = this .getComms().request
556:                        .getParameter(HIRE_DATE_DD);
557:                String address = this .getComms().request.getParameter(ADDRESS);
558:                String city = this .getComms().request.getParameter(CITY);
559:                String region = this .getComms().request.getParameter(REGION);
560:                String postalCode = this .getComms().request
561:                        .getParameter(POSTAL_CODE);
562:                String country = this .getComms().request.getParameter(COUNTRY);
563:                String homePhone = this .getComms().request
564:                        .getParameter(HOME_PHONE);
565:                String mobilePhone = this .getComms().request
566:                        .getParameter(MOBILE_PHONE);
567:                String email = this .getComms().request.getParameter(EMAIL);
568:                String notes = this .getComms().request.getParameter(NOTES);
569:                String isAdmin = this .getComms().request.getParameter(IS_ADMIN);
570:
571:                // Instantiate the page object
572:                EditHTML page = new EditHTML();
573:
574:                HTMLInputElement el = page.getElementTxtFirstName();
575:                if (null != firstName) {
576:                    el.setValue(firstName);
577:                } else {
578:                    el.setValue("");
579:                }
580:
581:                el = page.getElementTxtLastName();
582:                if (null != lastName) {
583:                    el.setValue(lastName);
584:                } else {
585:                    el.setValue("");
586:                }
587:
588:                el = page.getElementTxtLogin();
589:                if (null != login) {
590:                    el.setValue(login);
591:                } else {
592:                    el.setValue("");
593:                }
594:
595:                el = page.getElementTxtPassword();
596:                if (null != password) {
597:                    el.setValue(password);
598:                } else {
599:                    el.setValue("");
600:                }
601:
602:                el = page.getElementTxtTitle();
603:                if (null != title) {
604:                    el.setValue(title);
605:                } else {
606:                    el.setValue("");
607:                }
608:
609:                el = page.getElementTxtTitleOfCourtesy();
610:                if (null != titleOfCourtesy) {
611:                    el.setValue(titleOfCourtesy);
612:                } else {
613:                    el.setValue("");
614:                }
615:
616:                el = page.getElementTxtBirthDateYYYY();
617:                if (null != birthDateYYYY) {
618:                    el.setValue(birthDateYYYY);
619:                } else {
620:                    el.setValue("");
621:                }
622:
623:                el = page.getElementTxtBirthDateMM();
624:                if (null != birthDateMM) {
625:                    el.setValue(birthDateMM);
626:                } else {
627:                    el.setValue("");
628:                }
629:
630:                el = page.getElementTxtBirthDateDD();
631:                if (null != birthDateDD) {
632:                    el.setValue(birthDateDD);
633:                } else {
634:                    el.setValue("");
635:                }
636:
637:                el = page.getElementTxtHireDateYYYY();
638:                if (null != hireDateYYYY) {
639:                    el.setValue(hireDateYYYY);
640:                } else {
641:                    el.setValue("");
642:                }
643:
644:                el = page.getElementTxtHireDateMM();
645:                if (null != hireDateMM) {
646:                    el.setValue(hireDateMM);
647:                } else {
648:                    el.setValue("");
649:                }
650:
651:                el = page.getElementTxtHireDateDD();
652:                if (null != hireDateDD) {
653:                    el.setValue(hireDateDD);
654:                } else {
655:                    el.setValue("");
656:                }
657:
658:                el = page.getElementTxtAddress();
659:                if (null != address) {
660:                    el.setValue(address);
661:                } else {
662:                    el.setValue("");
663:                }
664:
665:                el = page.getElementTxtCity();
666:                if (null != city) {
667:                    el.setValue(city);
668:                } else {
669:                    el.setValue("");
670:                }
671:
672:                el = page.getElementTxtRegion();
673:                if (null != region) {
674:                    el.setValue(region);
675:                } else {
676:                    el.setValue("");
677:                }
678:
679:                el = page.getElementTxtPostalCode();
680:                if (null != postalCode) {
681:                    el.setValue(postalCode);
682:                } else {
683:                    el.setValue("");
684:                }
685:
686:                el = page.getElementTxtCountry();
687:                if (null != country) {
688:                    el.setValue(country);
689:                } else {
690:                    el.setValue("");
691:                }
692:
693:                el = page.getElementTxtHomePhone();
694:                if (null != homePhone) {
695:                    el.setValue(homePhone);
696:                } else {
697:                    el.setValue("");
698:                }
699:
700:                el = page.getElementTxtMobilePhone();
701:                if (null != mobilePhone) {
702:                    el.setValue(mobilePhone);
703:                } else {
704:                    el.setValue("");
705:                }
706:
707:                el = page.getElementTxtEmail();
708:                if (null != email) {
709:                    el.setValue(email);
710:                } else {
711:                    el.setValue("");
712:                }
713:
714:                //HTMLTextAreaElement tael=page.getElementTxtNotes();
715:                el = page.getElementTxtNotes();
716:                if (null != notes) {
717:                    el.setValue(notes);
718:                } else {
719:                    el.setValue("");
720:                }
721:
722:                el = page.getElementCbxIsAdmin();
723:                if (null != isAdmin) {
724:                    el.setChecked(true);
725:                } else {
726:                    el.setChecked(false);
727:                }
728:
729:                if (null == errorMsg) {
730:                    page.getElementErrorText().getParentNode().removeChild(
731:                            page.getElementErrorText());
732:                } else {
733:                    page.setTextErrorText(errorMsg);
734:                }
735:
736:                return page;
737:            }
738:
739:            /**
740:             * Method to save a new or existing employee to the database
741:             *
742:             * @param employee, the employee to be saved
743:             * @return html document
744:             * @exception HttpPresentationException
745:             */
746:            protected void saveEmployee(Employee theEmployee)
747:                    throws HttpPresentationException {
748:
749:                String firstName = this .getComms().request
750:                        .getParameter(FIRST_NAME);
751:                String lastName = this .getComms().request
752:                        .getParameter(LAST_NAME);
753:                String login = this .getComms().request.getParameter(LOGIN);
754:                String password = this .getComms().request
755:                        .getParameter(PASSWORD);
756:                String title = this .getComms().request.getParameter(TITLE);
757:                String titleOfCourtesy = this .getComms().request
758:                        .getParameter(TITLE_OF_COURTESY);
759:                String birthDateYYYY = this .getComms().request
760:                        .getParameter(BIRTH_DATE_YYYY);
761:                String birthDateMM = this .getComms().request
762:                        .getParameter(BIRTH_DATE_MM);
763:                String birthDateDD = this .getComms().request
764:                        .getParameter(BIRTH_DATE_DD);
765:                String hireDateYYYY = this .getComms().request
766:                        .getParameter(HIRE_DATE_YYYY);
767:                String hireDateMM = this .getComms().request
768:                        .getParameter(HIRE_DATE_MM);
769:                String hireDateDD = this .getComms().request
770:                        .getParameter(HIRE_DATE_DD);
771:                String address = this .getComms().request.getParameter(ADDRESS);
772:                String city = this .getComms().request.getParameter(CITY);
773:                String region = this .getComms().request.getParameter(REGION);
774:                String postalCode = this .getComms().request
775:                        .getParameter(POSTAL_CODE);
776:                String country = this .getComms().request.getParameter(COUNTRY);
777:                String homePhone = this .getComms().request
778:                        .getParameter(HOME_PHONE);
779:                String mobilePhone = this .getComms().request
780:                        .getParameter(MOBILE_PHONE);
781:                String email = this .getComms().request.getParameter(EMAIL);
782:                String notes = this .getComms().request.getParameter(NOTES);
783:                String isAdmin = this .getComms().request.getParameter(IS_ADMIN);
784:
785:                if (isNullField(firstName)
786:                        || isNullField(lastName)
787:                        || isNullField(login)
788:                        || isNullField(password)
789:                        || !areDateFieldsValid(birthDateYYYY, birthDateMM,
790:                                birthDateDD)
791:                        || !areDateFieldsValid(hireDateYYYY, hireDateMM,
792:                                hireDateDD)) {
793:                    throw new ProjectManagementPresentationException(
794:                            "Error adding employee", new Exception());
795:                }
796:
797:                try {
798:                    String birthDate = birthDateYYYY + "-" + birthDateMM + "-"
799:                            + birthDateDD;
800:                    String hireDate = hireDateYYYY + "-" + hireDateMM + "-"
801:                            + hireDateDD;
802:                    theEmployee.setFirstName(firstName);
803:                    theEmployee.setLastName(lastName);
804:                    theEmployee.setLogin(login);
805:                    theEmployee.setPassword(password);
806:                    theEmployee.setTitle(title);
807:                    theEmployee.setTitleOfCourtesy(titleOfCourtesy);
808:                    theEmployee.setBirthDate(Date.valueOf(birthDate));
809:                    theEmployee.setHireDate(Date.valueOf(hireDate));
810:                    theEmployee.setAddress(address);
811:                    theEmployee.setCity(city);
812:                    theEmployee.setRegion(region);
813:                    theEmployee.setPostalCode(postalCode);
814:                    theEmployee.setCountry(country);
815:                    theEmployee.setHomePhone(homePhone);
816:                    theEmployee.setMobilePhone(mobilePhone);
817:                    theEmployee.setEmail(email);
818:                    theEmployee.setNotes(notes);
819:                    theEmployee.setIsAdmin(isAdmin != null);
820:                    theEmployee.save();
821:                } catch (Exception ex) {
822:                    throw new ProjectManagementPresentationException(
823:                            "Error adding employee", ex);
824:                }
825:            }
826:
827:            private boolean isExistingLogin(Employee employee) {
828:                boolean isExistingLogin = false;
829:                String login = null;
830:                try {
831:                    login = this .getComms().request.getParameter(LOGIN).trim();
832:                } catch (Exception exc) {
833:                }
834:                if (!isNullField(login)) {
835:                    ProjectManagement pm = getApplication();
836:                    if (pm.getAdminUsername().equals(login)) {
837:                        isExistingLogin = true;
838:                    } else {
839:                        try {
840:
841:                            EmployeeManager employeeManager = EmployeeManagerFactory
842:                                    .getEmployeeManager("projectmanagement.business.employee.EmployeeManagerImpl");
843:                            Employee user = employeeManager.findEmployee(login);
844:                            if (user != null
845:                                    && (employee == null || !user.getHandle()
846:                                            .equals(employee.getHandle()))) {
847:                                isExistingLogin = true;
848:                            }
849:                        } catch (ProjectManagementException ex) {
850:                        }
851:                    }
852:                }
853:                return isExistingLogin;
854:            }
855:
856:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.