1 package phoneList.presentation; 2 3 import java.io.IOException ; 5 6 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 { 21 try{ 22 lookupPerson(comms); 23 }catch(Exception e){ 24 e.printStackTrace(); 25 } 26 } 27 28 public static void lookupPerson(HttpPresentationComms comms) throws Exception { 29 String 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 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 62 } catch(NullPointerException ex) { 63 64 } 65 comms.response.writeDOM(edit); 66 67 } 68 69 private static void sendErrPage(HttpPresentationComms comms, String msg) throws Exception { 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 |