LeadsIndexList.java

00001 
00025 package org.openmobileis.examples.mycrm.terminal.services;
00026 
00027 import org.openmobileis.common.util.collection.Array;
00028 import org.openmobileis.common.util.exception.DatabaseException;
00029 import org.openmobileis.common.util.exception.ServiceException;
00030 import org.openmobileis.examples.mycrm.data.Account;
00031 import org.openmobileis.examples.mycrm.data.Leads;
00032 import org.openmobileis.examples.mycrm.data.fodb.AccountFactory;
00033 import org.openmobileis.examples.mycrm.data.fodb.LeadsFactory;
00034 import org.openmobileis.services.servlet.IndexServletContentListener;
00035 
00036 import freemarker.template.SimpleHash;
00037 import freemarker.template.SimpleList;
00038 import freemarker.template.TemplateModelRoot;
00039 
00040 /*
00041  * Title:        OpenMobileIS project source <BR>
00042  * Description:
00043  * @author      Philippe Delrieu
00044  * @since       JDK 1.1
00045  * @version 1.0.
00046  */
00047 
00048 public final class LeadsIndexList implements IndexServletContentListener {
00049 
00053   public LeadsIndexList() {
00054     super();
00055   }
00056 
00057   /* (non-Javadoc)
00058    * @see org.openmobileis.services.servlet.IndexServletContentListener#addContent(freemarker.template.TemplateModelRoot)
00059    */
00060   public void addContent(TemplateModelRoot modelRoot) throws ServiceException {
00061     try   {
00062       
00063       Array leadsList = LeadsFactory.getManager().getAllLeads();
00064       
00065       // construct the SimpleList to fill HTML array (see the template).
00066       SimpleList showList = new SimpleList();
00067       SimpleHash dataStruct;
00068       java.text.SimpleDateFormat formater = new java.text.SimpleDateFormat("MM/dd/yyyy", java.util.Locale.FRANCE);
00069       for (int i = 0; i < leadsList.size(); i++) {
00070         dataStruct = new SimpleHash();
00071         Leads lead = (Leads)leadsList.get(i);
00072         dataStruct.put("id", lead.getId());
00073         Account account = AccountFactory.getManager().getAccount(lead.getIdaccount());
00074         dataStruct.put("accountid",  account.getId());
00075         dataStruct.put("accountname",  account.getName());
00076         dataStruct.put("amount",  Integer.toString(lead.getAmount()));
00077         dataStruct.put("date",  formater.format(lead.getCloseDate()).toString());
00078          showList.add(dataStruct);
00079       }
00080       modelRoot.put("leadsList", showList);
00081     } catch (DatabaseException ex) {
00082       throw new ServiceException(ex);
00083     }
00084   }
00085 
00086 }

Generated on Mon Dec 4 11:03:27 2006 for OpenMobileIS by  doxygen 1.5.1-p1