2017-10-05 4 views
0

xe : beanNamePicker에 사용할 Java 클래스를 설정했습니다. 어떻게 든 만든 SimplePickerResult를 결과 집합에 추가 할 수 없습니다.xe : beanNamePicker, 메모보기에서 내 값을 결과 집합으로 가져올 수 없음

package se.myorg.myproject.app; 

import java.io.IOException; 
import java.util.List; 
import java.util.Properties; 
import java.util.TreeSet; 

import se.sebank.namis.utils.Utils; 

import lotus.domino.Database; 
import lotus.domino.Document; 
import lotus.domino.DocumentCollection; 
import lotus.domino.NotesException; 
import lotus.domino.View; 

import com.ibm.xsp.complex.ValueBindingObjectImpl; 
import com.ibm.xsp.extlib.component.picker.data.INamePickerData; 
import com.ibm.xsp.extlib.component.picker.data.IPickerEntry; 
import com.ibm.xsp.extlib.component.picker.data.IPickerOptions; 
import com.ibm.xsp.extlib.component.picker.data.IPickerResult; 
import com.ibm.xsp.extlib.component.picker.data.SimplePickerResult; 

public class DirectoryNamePicker extends ValueBindingObjectImpl implements INamePickerData { 

    private Utils utils; 

    Properties props; 

    public DirectoryNamePicker(){ 
     //constructor 
     utils = new Utils(); 
     utils.printToConsole(this.getClass().getSimpleName().toString() + " - DirectoryNamePicker() // constructor"); 
     try { 
      props = utils.getDataSourceProperties(); 
     } catch (IOException e) { 
      // TODO Auto-generated catch block 
      e.printStackTrace(); 
     } 
    } 

    public String[] getSourceLabels() { 
    // TODO Auto-generated method stub 
    return null; 
    } 

    public boolean hasCapability (final int arg0) { 
    // TODO Auto-generated method stub 
    return false; 
    } 

    public List<IPickerEntry> loadEntries (final Object[] arg0, final String[] arg1) { 
    // TODO Auto-generated method stub 
    return null; 
    } 

    @SuppressWarnings("unchecked") 
public IPickerResult readEntries (final IPickerOptions options) { 
    String startKey = options.getStartKey(); 
    int count = options.getCount(); 
    TreeSet<IPickerEntry> entries = new TreeSet<IPickerEntry>(); 
    if (startKey != null) { 
     // User is performing a search 
     try { 
      entries = this.dirLookup(startKey, count); 
     } catch (NotesException e) { 
      System.err.println("Exception trying to perform directory lookup: " + e.getMessage()); 
      e.printStackTrace(); 
     } 
     } 
    return new SimplePickerResult((List<IPickerEntry>) entries, -1); 
    } 

    public TreeSet<IPickerEntry> dirLookup(final String search, final int limit) throws NotesException { 
    TreeSet<IPickerEntry> result = new TreeSet<IPickerEntry>(); 

    String server = props.getProperty("server_notesname"); 
    String filepath = props.getProperty("db_project_data"); 
    Database db = utils.getSession().getDatabase(server, filepath); 

    View vw = db.getView("vw_all_todo_namespicker"); 
    vw.setAutoUpdate(false); 

    DocumentCollection dc = vw.getAllDocumentsByKey(search, false); 
    int count = 0; 
    Document tmpdoc; 
    Document doc = dc.getFirstDocument(); 

    while (doc != null && count < limit) { 
     String person = doc.getItemValueString("app_ProjMgrName"); 
     IPickerEntry entry = new SimplePickerResult.Entry(person, person); 
     result.add(entry); 
     // result.add(entry does not seem to work 
     tmpdoc = dc.getNextDocument(); 
     doc.recycle(); 
     doc = tmpdoc; 
     count = count +1; 
     }  
    vw.setAutoUpdate(true); 
    return result; 
    } 

} 

내가 잘못한 것을 말해 줄 수있는 사람이 있습니까? 나는 arraylist 대신에 treeset을 선택했다. 이것은 여러 항목이 많은보기로 이동하여 중복을 원하지 않으므로 값으로 정렬해야하기 때문입니다.

+0

이름 선택기 대화 상자에서 검색을 수행하면 작동합니까? 코드는 검색 할 때 채워진 결과 집합만을 반환합니다. –

+0

예 검색을 수행합니다. 내 문서 컬렉션에있는 문서의 양을 출력하면 일치하는 문서가 있음을 알 수 있습니다. –

답변

2

당신은 줄에서 (목록)에 TreeSet의 캐스팅하고 : 그 캐스트 있도록 SimplePickerResult이 목록이 필요하기 때문에 (이 컬렉션을 허용하지 않습니다)

return new SimplePickerResult((List<IPickerEntry>) entries, -1); 

있지만, TreeSet의 목록을 구현하지 않습니다 실패 할 것이다. 아마 ArrayList로 다시 변경해야 할 것입니다. 정렬을 위해 SimplePickerResult.Entry에 내장 된 비교 메서드가 없으므로 java.util.Collections.sort (List 목록, Comparator c)를 entry.getLabel() 값을 비교하는 사용자 지정 비교기와 함께 사용해보십시오.