01: package phoneList.presentation;
02:
03: // Standard imports
04: import java.io.IOException;
05:
06: // Enhydra SuperServlet imports
07: import com.lutris.appserver.server.httpPresentation.HttpPresentation;
08: import com.lutris.appserver.server.httpPresentation.HttpPresentationComms;
09: import com.lutris.appserver.server.httpPresentation.HttpPresentationException;
10: import com.lutris.appserver.server.httpPresentation.ClientPageRedirectException;
11: import org.w3c.dom.html.HTMLInputElement;
12:
13: import phoneList.spec.*;
14:
15: public class EditPresentation implements HttpPresentation {
16:
17: private static EditHTML edit;
18:
19: public void run(HttpPresentationComms comms)
20: throws HttpPresentationException, IOException {
21: try {
22: lookupPerson(comms);
23: } catch (Exception e) {
24: e.printStackTrace();
25: }
26: }
27:
28: public static void lookupPerson(HttpPresentationComms comms)
29: throws Exception {
30: String id = comms.request.getParameter("id");
31: Person p = null;
32: try {
33: edit = (EditHTML) comms.xmlcFactory.create(EditHTML.class);
34: PhoneList phoneList = PhoneListFactory
35: .getPhoneList("phoneList.business.PhoneListImpl");
36: if (id != null)
37: p = phoneList.getById(id);
38: if (p == null) {
39: String err = comms.request
40: .getAppFileURIPath("ErrorPresentation.po");
41: ClientPageRedirectException e = new ClientPageRedirectException(
42: err);
43: e.addArgument("err", "Internal error: id not found.");
44: throw e;
45: }
46:
47: HTMLInputElement idHidden = edit.getElementId();
48: idHidden.setValue(id);
49:
50: HTMLInputElement first = edit.getElementFirst_text();
51: first.setValue(p.getFirstName());
52:
53: HTMLInputElement last = edit.getElementLast_text();
54: last.setValue(p.getLastName());
55:
56: HTMLInputElement phone = edit.getElementPhone_text();
57: phone.setValue(p.getPhoneNumber());
58:
59: edit.setTitle("Editing ");
60: edit.setTextFirst(p.getFirstName());
61: edit.setTextLast(p.getLastName());
62: /*
63: * Catch Null pointer exception ( we canot make a instances of classes from business layer when we run phoneBookClient_pres )
64: * We need to allow phoneBookClient_pres to be functional ,return default HTML page
65: */
66: } catch (NullPointerException ex) {
67:
68: }
69:
70: comms.response.writeDOM(edit);
71:
72: }
73:
74: private static void sendErrPage(HttpPresentationComms comms,
75: String msg) throws Exception {
76: comms.response
77: .writeHTML("<HTML><HEAD><TITLE>ERROR</TITLE></HEAD><BODY>");
78: comms.response.writeHTML("<h1>" + msg + "</h1><p>");
79: comms.response
80: .writeHTML("<a href=ListPresentation.po>Return</a>");
81: comms.response.writeHTML("</BODY></HTML>");
82: }
83: }
|