Xpages-在Arraylist中传递<ahref>

时间:2019-03-05 10:39:45

标签: java arraylist xpages href xpages-ssjs

我正在尝试向Arraylist添加href,这很好地添加到了Arraylist,但是链接断开了。网址中问号(?)之后的所有内容均未包含在链接中。

有什么我想念的吗,代码如下:

private String processUpdate(Database dbCurrent) throws NotesException {

int intCountSuccessful = 0;
View vwLookup = dbCurrent.getView("DocsDistribution");
ArrayList<String> listArray = new ArrayList<String>();
Document doc = vwLookup.getFirstDocument();

while (doc != null) {
    String paperDistro = doc.getItemValueString("DistroRecords");
    if (paperDistro.equals("")) {
        String ref = doc.getItemValueString("ref");
        String unid = doc.getUniversalID();
        // the link generated when adding to Arraylist is broken
        listArray.add("<a href=\"gandhi.w3schools.com/testbox.nsf/distro.xsp?documentId=\"+ unid + \"&action=openDocument\">" + ref + "</a>");
    }
    Document tmppmDoc = vwLookup.getNextDocument(doc);
    doc.recycle();
    doc = tmppmDoc;
}

Collections.sort(listArray);

String listString = "";
for (String s : listArray) {
    listString += s + ", \t";
}

return listString;

}

1 个答案:

答案 0 :(得分:3)

您遇到"转义为unid值的问题,因此您的网址变成了gandhi.w3schools.com/testbox.nsf/distro.xsp?documentId="+ unid + "&action=openDocument

如果您使用String.format()和单引号来生成a标签,则会更容易阅读:

listArray.add(String.format(
    "<a href='gandhi.w3schools.com/testbox.nsf/distro.xsp?documentId=%s&action=openDocument'>%s</a>", 
    unid, ref));