0

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!

Community
  • 1
  • 1
Dan
  • 940
  • 2
  • 14
  • 42

1 Answers1

1

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

stwissel
  • 20,110
  • 6
  • 54
  • 101
  • Based on the table I building above, I am limited to client side JavaScript to call from the onclick event. A server side JavaScript is not recognized by the dialog in my trials. I created a server side JavaScript library, made it a Resource to the XPage and everytime I clicked link I would get a "updateDcoument is not defined." When I made it a client side JavaScript library, it had no problems. In the onclick event, how do I get a handle on the document? I looked at the link provided above, but I did not see how I could implement in my code. Thanks – Dan Oct 10 '12 at 20:26
  • You are missing the piece where you call back to the server. You can't just call a SSJS function in a client side button – stwissel Oct 11 '12 at 08:48
  • How do I make this call back to the server? Is this in the updateDocument() function? Can you show me a sample? Thanks for your patience! – Dan Oct 11 '12 at 14:00
  • All you need was in my initial answer (it has links to the XPages Wiki). Did you check them? – stwissel Oct 11 '12 at 18:59
  • I read the link, but what id am I passing to partially refresh? I don't mean to be a pain on this. I have the code working using for example: `code`thisField = document.getElementById("view:_id1:_id2:facetMiddle:include1:reqInfoTab:sr_Name1"); thisField.value = name; `code` But it doesn't seem to be the correct way to handle. – Dan Oct 11 '12 at 22:34
  • 1
    almost there. You put that into a script block and write thisField = document.getElementById("#{id:sr_Name1‌​}"); - that is the client side version. If you did bind the values of your dialogbox to the backend fields, you refresh the dialogbox control. The exampled code in the extlib does that. That would be serverside then. – stwissel Oct 14 '12 at 12:59