0
votes

I have an XPage with a Dialog control from the Extension Library.

The dialog works fine -- opens, does what it needs to do, however, when I try to update the "parent" document, it does not work.

I have the XPage data source as Domino Document called document1. I added this after reading: When I save a document from an extension library dialog box some values are blank

<xp:this.data>
<xp:dominoDocument var="document1" formName="speakerReq"></xp:dominoDocument
</xp:this.data>

On the dialog control, I have a Search button which calls a servlet and returns JSON that is parsed and built into an HTML table. The first cell is a link which calls a function from a client side JavaScript library when it is clicked. The function is to update the "parent" document with values from the returned JSON as well as close the dialog.

It can call the function when I test with just an alert() statement in that function, however, when I try to update the "parent" document, it does not recognize that.

I have tried to pass the "document1" object but once I get to the dialog, it says it does not exist, so the link is failing.

Here is the code snippet where the link is built:

        // Let's build the row...
        cell = document.createElement("td");
        resultLink = document.createElement("a");
        resultLink.setAttribute("class", "linkText");
        resultLink.setAttribute("href", "#");
        resultLink.setAttribute("onclick", "javascript:updateDocument(document1, '" + bpName + "', '" + bpEmail + "', '" + bpPhone + "', '" + bpTitle + "', '" + bpCountry + "', '" + bpLoc + "');");
        resultLink.appendChild(document.createTextNode(bpName));
        cell.appendChild(resultLink);
        row.appendChild(cell);

How do I get a handle on the document1 object on the client side so I can update those fields on the "parent" document as well as close the dialog?

Code:

function updateDocument(doc, name, email, phone, job, country, location) {

var thisField;

// Need to update the document with the selected values...
thisField = doc.getElementById("#{id:sr_Name1}");
thisField.value = name;

thisField = doc.getElementById("#{id:sr_Title1}");
thisField.value = email;

thisField = doc.getElementById("#{id:sr_Phone1}");
thisField.value = phone;

thisField = doc.getElementById("#{id:sr_Email1}");
thisField.value = job;

thisField = doc.getElementById("#{id:sr_Location1}");
thisField.value = location + " - " + country;

} 

Thanks!

1

1 Answers

1
votes

Seems you are mixing CSJS and SSJS up. The code snippet runs in the browser, but you try to execute server side code. This can't work. You need to post back your data to the server and handle the data there. The XPages Wiki has some ideas you might find useful.

Clarification:

Rule of thumb: anything that lands as JavaScript in your browser cannot have SSJS in it. So you can use anything DOM, but NO session, database, document1 etc. SSJS libraries are invisible to CSJS, so you can't call these methods. You can have a button in your page where you define both CSJS and SSJS. The client side would execute first and then do a refresh (partial or full).

Also your code above: getElementById is CSJS -> can't use that in a SSJS, while doc is as NotesDocumentDatasource -> doesn't have getElementById.

Furthermore: there is no "parent" element. The dialogbox is just another part of the local DOM (this is not NotesUIWorkspace.dialogbox). Check the XPagesWiki for samples