KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > pim > presentation > enhydrapim > Add


1 /*
2  * Created on May 6, 2005
3  *
4  * TODO To change the template for this generated file go to
5  * Window - Preferences - Java - Code Style - Code Templates
6  */

7 package org.enhydra.pim.presentation.enhydrapim;
8
9 import org.enhydra.pim.business.PersonManagerI;
10 import org.enhydra.pim.business.api.OwnerI;
11 import org.enhydra.pim.business.api.PersonI;
12 import org.enhydra.pim.presentation.BasePO;
13 import org.enhydra.pim.spec.PersonManagerFactory;
14 import org.enhydra.xml.xmlc.XMLObject;
15
16 import com.lutris.appserver.server.httpPresentation.ClientPageRedirectException;
17 import com.lutris.appserver.server.httpPresentation.HttpPresentationException;
18
19 /**
20  * @author P.Djojic May 6, 2005 1:25:19 AM
21  *
22  * TODO Add
23  */

24 public class Add extends BasePO {
25
26
27     String JavaDoc ID_FIRSTNAME = "firstName";
28     String JavaDoc ID_LASTNAME = "lastName";
29     String JavaDoc ID_NICKNAME = "nickName";
30     String JavaDoc ID_NOTE = "noteTextArea";
31
32
33
34
35     /*
36      * (non-Javadoc)
37      *
38      * @see org.enhydra.pim.presentation.enhydrapim.BasePO#handleDefault()
39      */

40     public XMLObject handleDefault() throws HttpPresentationException {
41         return showPage();
42     }
43     
44     /*
45      * (non-Javadoc)
46      *
47      * @see org.enhydra.pim.presentation.enhydrapim.BasePO#handleDefault()
48      */

49     public XMLObject handleAddAddItem() throws HttpPresentationException {
50
51         String JavaDoc firstName = this.getComms().request.getParameter(ID_FIRSTNAME);
52         String JavaDoc lastName = this.getComms().request.getParameter(ID_LASTNAME);
53         String JavaDoc nickName = this.getComms().request.getParameter(ID_NICKNAME);
54         String JavaDoc note = this.getComms().request.getParameter(ID_NOTE);
55         
56         if (nickName == null) nickName="";
57         if (note == null) note="";
58         
59         if ((firstName== null || lastName== null) ||
60                 (firstName.length()==0 || firstName.length()==0 )){
61             return showErrorPage("FirstName and LastName can not be empty");
62         }
63         
64         OwnerI user = null; //user
65
PersonI person = null;
66         PersonManagerI pManager = null ;
67         try {
68             user = this.getSessionData().getUser();
69             if (user!=null){
70                 pManager = PersonManagerFactory.getPersonManager();
71                 person = pManager.newPerson(user,firstName,lastName,nickName,note);
72                 pManager.addPerson(person,user);
73             }else {
74                 return showErrorPage("Invalid access");
75             }
76         } catch (Exception JavaDoc e) {
77             return showErrorPage("Error during database writing");
78         }
79         throw new ClientPageRedirectException(Common.REDIRECT_VIEW);
80     }
81     
82     
83     
84     /* (non-Javadoc)
85      * @see org.enhydra.pim.presentation.BasePO#loggedInUserRequired()
86      */

87     protected boolean loggedInUserRequired() {
88         // TODO Auto-generated method stub
89
return true;
90     }
91     
92     /**
93      * display page
94      *
95      * @return html document
96      * @exception HttpPresentationException
97      */

98     public XMLObject showPage() throws HttpPresentationException {
99         AddHTML page = (AddHTML) myComms.xmlcFactory.create(AddHTML.class);
100         return page;
101     }
102
103     
104 }
105
Popular Tags