Search code examples
javaarraylistxpageshrefxpages-ssjs

Xpages - Passing <ahref> in Arraylist


I'm trying to add a href to Arraylist and this adds nicely to the Arraylist, but the link is broken. Everything after the question mark (?) in the URL is not included in the link.

Is there anything that I'm missing, code below:

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;

}

Solution

  • You have a problem with " escaping around unid value due to which you URL becomes gandhi.w3schools.com/testbox.nsf/distro.xsp?documentId="+ unid + "&action=openDocument.

    It would be easier to read if you use String.format() and single quotes to generate the a tag:

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