Lothar Mueller
Lothar Mueller

Reputation: 2528

How can I bind a panel to either an existing doc datasource or to a newly created document?

In an xpage which is bound to its onw document datasource ("parent") I'm having a repeat control showing some view data (containing dependant docs, or "responses") as well as a button to create new "response"-documents. The responses' data are displayed in a separate panel on the same page which is only visible upon selection of a response from the repeat or upon creation of a new response. The doc datasource is bound to a panel surrounding the "dynamic" response doc panel, like this:

<xp:panel id="panelFlDs">
    <xp:this.data>
        <xp:dominoDocument var="dsDocFileLink" formName="fmFileLink"
            ignoreRequestParams="true">
            <xp:this.documentId><![CDATA[#{javascript:viewScope.get("unidFileLink")}]]></xp:this.documentId>
        </xp:dominoDocument>
    </xp:this.data>
    <xp:panel id="panelFlForm">
        <xp:this.rendered><![CDATA[#{javascript:viewScope.get("showDialogFileLink")=="1"}]]></xp:this.rendered>
        <xc:ccFormFileLink></xc:ccFormFileLink>
    </xp:panel>
</xp:panel>

As you can see I'm trying to bind my datasource to a docUnid which is passed on using a viewScope. This works fine for existing docs, as well (with a caveat, see below) for new ones, where I simply remove the viewScope variable before showing the panel. For new responses I also set some inherited field values from the parent using the same button code as in

dsDocFileLink.replaceItemValue("flType", "flTypeFile");
dsDocFileLink.replaceItemValue("glBlockID", dsDocFileLinkBlock.getItemValueString("glBlockID"));
dsDocFileLink.replaceItemValue("histCreatedOn", @Now());

etc.

The caveat is that I cannot create two new docs in a row: the second and all following new docs seem to use the same datasource as the first: their editable fields show the values from the previously edited new doc.

I tried creating new datasource objects (and clearing old ones) following Sven Hasselbachs great examples (here and here), but as Sven notes in his blog entry, I cannot immediately use my newly created datasource. Thus I can create a new ds, but I cannot use inheritance the way I plan to do it because the datasource is not yet usable.

Before I try to rework everything and start inheritance at the datasource level using editable fields with default values etc.: is this even the correct way for my task, or should I rather take another turn somewhere?

EDIT: I just tried to do without inheritance, i.e. creating a new repoonse, fill in some values, then save&close (remark: "close" hides the response data panel), then create a second new response. Result: again the second response contains the values I filled in for the first one. My create modified create button now looks like this:

var panelFlDs:com.ibm.xsp.component.UIPanelEx = getComponent("panelFlDs");
var ds = new com.ibm.xsp.model.domino.DominoDocumentData();
ds.setVar("dsDocFileLink");
ds.setFormName("fmFileLink");
panelFlDs.getData().clear();
panelFlDs.addData(ds);
viewScope.remove("unidFileLink");
viewScope.put("showDialogFileLink", "1");

Best regards

Lothar

Upvotes: 1

Views: 661

Answers (1)

David Leedy
David Leedy

Reputation: 3593

Go into all properties of the DataSource for the repeat control.And in there is a "Scope" setting. the default is viewScope. Change it to requestScope so it doesn't retain the first document that you create. Then every time should be a new document.

Upvotes: 3

Related Questions