KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > phoneList > presentation > EditPresentation


1 package phoneList.presentation;
2
3 // Standard imports
4
import java.io.IOException JavaDoc;
5
6 // Enhydra SuperServlet imports
7
import com.lutris.appserver.server.httpPresentation.HttpPresentation;
8 import com.lutris.appserver.server.httpPresentation.HttpPresentationComms;
9 import com.lutris.appserver.server.httpPresentation.HttpPresentationException;
10 import com.lutris.appserver.server.httpPresentation.ClientPageRedirectException;
11 import org.w3c.dom.html.HTMLInputElement;
12
13
14 import phoneList.spec.*;
15
16 public class EditPresentation implements HttpPresentation {
17
18   private static EditHTML edit;
19
20   public void run(HttpPresentationComms comms) throws HttpPresentationException, IOException JavaDoc {
21     try{
22       lookupPerson(comms);
23     }catch(Exception JavaDoc e){
24       e.printStackTrace();
25     }
26   }
27
28   public static void lookupPerson(HttpPresentationComms comms) throws Exception JavaDoc {
29       String JavaDoc id = comms.request.getParameter("id");
30       edit = (EditHTML)comms.xmlcFactory.create(EditHTML.class);
31       Person p = null;
32       PhoneList phoneList = PhoneListFactory.getPhoneList("phoneList.business.PhoneListImpl");
33     try{
34       if (id != null)
35           p = phoneList.getById(id);
36       if (p == null) {
37           String JavaDoc err = comms.request.getAppFileURIPath("ErrorPresentation.po");
38           ClientPageRedirectException e = new ClientPageRedirectException(err);
39           e.addArgument("err", "Internal error: id not found.");
40           throw e;
41       }
42
43       HTMLInputElement idHidden = edit.getElementId();
44       idHidden.setValue(id);
45
46       HTMLInputElement first = edit.getElementFirst_text();
47       first.setValue(p.getFirstName());
48
49       HTMLInputElement last = edit.getElementLast_text();
50       last.setValue(p.getLastName());
51
52       HTMLInputElement phone = edit.getElementPhone_text();
53       phone.setValue(p.getPhoneNumber());
54
55       edit.setTitle("Editing ");
56       edit.setTextFirst(p.getFirstName());
57       edit.setTextLast(p.getLastName());
58   /*
59  * Catch Null pointer exception ( we canot make a instances of classes from business layer when we run phoneBookClient_pres )
60  * We need to allow phoneBookClient_pres to be functional ,return default HTML page
61  */

62     } catch(NullPointerException JavaDoc ex) {
63         
64         }
65       comms.response.writeDOM(edit);
66
67   }
68
69     private static void sendErrPage(HttpPresentationComms comms, String JavaDoc msg) throws Exception JavaDoc {
70       comms.response.writeHTML("<HTML><HEAD><TITLE>ERROR</TITLE></HEAD><BODY>");
71       comms.response.writeHTML("<h1>" + msg + "</h1><p>");
72       comms.response.writeHTML("<a HREF=ListPresentation.po>Return</a>");
73       comms.response.writeHTML("</BODY></HTML>");
74   }
75 }
76
77
78
79
Popular Tags