Пример #1
0
 protected void init() {
   // System.err.println( "INIT: _sc.getBeanName() = " + _sc.getBeanName() );
   try {
     if (_cache == null) {
       _cache = ObjectCacheFactory.defaultObjectCache();
     }
     _sod = SODUtils.getInstance();
     // Try to retrive from cache.
     _sc.setReturnCount(new Boolean(true));
     _sc.setReturnObjects(new Boolean(true));
     SearchResult sr = _cache.get(_sc);
     if (sr == null) {
       sr = _sc.search();
       _cache.put(_sc, sr);
     }
     _count = sr.getCount().intValue();
     List newItems = Arrays.asList(sr.getResultSet());
     for (Iterator i = newItems.iterator(); i.hasNext(); ) {
       _objects.add(i.next());
     }
   } catch (Exception ex) {
     ex.printStackTrace();
     throw new RuntimeException("Error initializing: " + ex.toString());
   }
 }
Пример #2
0
 public PagerItem[] getItems(int startIdx, int numItems) throws Exception {
   //     System.err.println( "getItems(): startIdx = " + startIdx +
   // 			", numItems = " + numItems );
   int pis = startIdx + numItems;
   _sc.setStartAt(new Integer(startIdx + 1));
   _sc.setMaxRecordset(new Integer(numItems));
   SearchResult sr = _cache.get(_sc);
   if (sr == null) {
     sr = _sc.search();
     _cache.put(_sc, sr);
   }
   _objects = Arrays.asList(sr.getResultSet());
   // System.err.println( "_objects.size() = " + _objects.size() );
   pis = Math.min(_objects.size(), numItems);
   if (pis < 0) {
     pis = 0;
   }
   // System.err.println( "pis = " + pis );
   PagerItem[] items = new PagerItem[pis];
   SearchableObject so = _sod.getSearchableObject(_sc.getBeanName());
   for (int i = 0; i < items.length; i++) {
     // Object obj = _objects.get( startIdx + i );
     Object obj = _objects.get(i);
     Object idObj = CaBIOUtils.getProperty(obj, "id");
     String id = (idObj != null ? idObj.toString() : "");
     // System.err.println( "creating pi for " + obj.getClass().getName() + ":" + id );
     List labelProps = so.getLabelProperties();
     List assocs = getNavigableAssociations(so);
     List vals = new ArrayList();
     for (ListIterator j = labelProps.listIterator(); j.hasNext(); ) {
       Object val = CaBIOUtils.getProperty(obj, ((String) j.next()).trim());
       if (val != null) {
         vals.add(val.toString());
       } else {
         vals.add("");
       }
     }
     if (_eventHandler != null) {
       for (ListIterator j = assocs.listIterator(); j.hasNext(); ) {
         Association assoc = (Association) j.next();
         vals.add(
             "<a href=\"javascript:"
                 + _eventHandler
                 + "('"
                 + obj.getClass().getName()
                 + "', '"
                 + id
                 + "', '"
                 + assoc.getRole()
                 + "')\">"
                 + assoc.getLabel()
                 + getCountString(obj, assoc.getRole())
                 + "</a>");
       }
     }
     items[i] = new PagerItemImpl(id, (String[]) vals.toArray(new String[vals.size()]));
   }
   return items;
 }