Ejemplo n.º 1
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;
 }
Ejemplo n.º 2
0
 public CaBIOPagerDataSource2(String beanName, String eh) {
   try {
     _sc = CaBIOUtils.newSearchCriteria(beanName);
     _sc.setMaxRecordset(new Integer(500));
   } catch (Exception ex) {
     ex.printStackTrace();
     throw new RuntimeException(
         "Error creating search criteria for " + beanName + ": " + ex.toString());
   }
   _eventHandler = eh;
   init();
 }