1 7 8 package projectmanagement.presentation.projects; 9 10 import projectmanagement.presentation.*; 11 import projectmanagement.spec.customer.*; 12 13 import org.w3c.dom.*; 14 import org.w3c.dom.html.*; 15 16 import com.lutris.appserver.server.httpPresentation.HttpPresentation; 18 import com.lutris.appserver.server.httpPresentation.HttpPresentationComms; 19 import com.lutris.appserver.server.httpPresentation.HttpPresentationException; 20 21 import java.io.IOException ; 23 24 27 public class Controls implements HttpPresentation { 28 29 32 private static String CUSTOMER = "customer"; 33 34 public void run(HttpPresentationComms comms) throws HttpPresentationException, IOException { 35 ControlsHTML page=new ControlsHTML(); 36 37 String customer = comms.request.getParameter(CUSTOMER); 38 HTMLSelectElement sel=page.getElementCboCustomers(); 39 fillSelection(page,sel,customer); 40 41 comms.response.writeDOM(page); 42 } 43 44 private void fillSelection (ControlsHTML page,HTMLSelectElement cboCustomers, 45 String selectedCustomerID) throws ProjectManagementPresentationException { 46 HTMLOptionElement optCustomer = page.getElementOptCustomer(); 47 48 try { 49 50 CustomerManager customerManager = CustomerManagerFactory.getCustomerManager("projectmanagement.business.customer.CustomerManagerImpl"); 51 Customer[] customers = customerManager.getAllCustomers(); 52 53 optCustomer.removeChild(optCustomer.getFirstChild()); 55 56 57 HTMLOptionElement clonedOption = (HTMLOptionElement)optCustomer.cloneNode(true); 59 clonedOption.setValue(""); 60 String all="All"; 61 Node optionTextNode = clonedOption.getOwnerDocument(). 62 createTextNode(all); 63 clonedOption.appendChild(optionTextNode); 64 clonedOption.setAttribute("selected","selected"); 65 cboCustomers.appendChild(clonedOption); 68 69 70 71 73 if (customers!=null) { 74 for (int i=0; i<customers.length; i++) { 75 Customer c=customers[i]; 76 clonedOption = (HTMLOptionElement)optCustomer.cloneNode(true); 84 clonedOption.setValue(c.getHandle()); 85 optionTextNode = clonedOption.getOwnerDocument(). 86 createTextNode(c.getCompanyName()); 87 clonedOption.appendChild(optionTextNode); 88 if (selectedCustomerID!=null && c.getHandle().equals(selectedCustomerID)) { 89 clonedOption.setAttribute("selected","selected"); 90 } 91 cboCustomers.appendChild(clonedOption); 94 } 95 } 96 cboCustomers.removeChild(optCustomer); 97 98 102 } catch(NullPointerException ex) { 103 104 } catch (Exception ex) { 105 throw new ProjectManagementPresentationException("Error populating customer list: ", ex); 107 } 108 109 110 } 111 112 } 113 | Popular Tags |