简体   繁体   中英

XPages - Lotus Domino Java - getDocumentByKey

In a Java class in my XPages application, I'm trying to get a handle on a Notes Document in a Notes View. The Notes View contains several Notes Documents. To get the Notes Document I want, I use 2 keys. This produces an error. If I use just one key, the first Notes Document in the Notes View is returned. The Notes View contains two sorted columns. The first column contains the empLang value, the second column contains the templateType value. Here is my code:

    String empLang = "en";
    String templateType = "C";
    Database dbCurr = session.getCurrentDatabase(); 
    String viewName = "vieAdminTemplates" + empLang;
    View tview = dbCurr.getView(viewName);
    Vector viewKey = new Vector();
    viewKey.addElement(empLang);
    viewKey.addElement(templateType); // this line causes the code to fail
    Document templateDoc = tview.getDocumentByKey(viewKey);

What could be the cause of this problem?

A couple of ideas

1) You could concatenate the key into a single column since you said that worked. Something like 'en~C'

2) You could use the database.search method where you include a string of formula language that isolates the document you want. It returns a collection, and then you pull the document from there.

getDocumentByKey works with multiple columns. There's a known problem with doubles, but you're not hitting that there. One thing that stands out is the second column is just a single letter. That could be considered as a Char instead of a String, either when you do addElement or by the view.

I'd recommend debugging out what data type they are. viewKey.get(1).getClass().getName() I think gives you the class it's stored as. Doing the same for the View Column value.

When you say it causes the code to fail, how does it fail? Does it just not return anything or throw an error?

My next step would be to try testing it where the View and the Vector contain more than one character, eg "CC", to help check if there's an underlying issue with Java getDocumentByKey and single characters.

I'm very sorry. The problem here is that the view name in the code is incorrect. There is a view "vieAdminTemplates" but it does not have a second column containing the value "C". With the correct view, the code works fine. Thanks for taking the time to respond to my question.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM