XPages save data source and new doc changes previo

2019-02-21 00:46发布

问题:

I have a document data source (create document with no parent id) bound to a panel. Within the panel I have 2 other panels. On completing the fields in panel 1 I click a link to reveal the 2nd panel and that has a save button on it. Once saved the document appears in the db correctly.

The save buttons does a dds save and then clears all fields and does a partial update on the outer panel and a partial execute on that panel too as I have other dds on the XPage outside of my main panel.

If I now create another document the previous document gets updated rather than create a new doc. I've tried different scope for the dds and other options. Not sure what to try next.

Anyone know what the problem is?

回答1:

Here is a example how you can add a new datasource with a partial refresh:

<xp:panel id="myPanel">
    <xp:this.data>
        <xp:dominoDocument var="document1"></xp:dominoDocument>
    </xp:this.data>
    <xp:br></xp:br>
    <xp:inputText id="inputText1" value="#{document1.Test}"></xp:inputText>
    <xp:br></xp:br>
    <xp:br></xp:br>
    <xp:button value="Save" id="buttonSave">
        <xp:eventHandler event="onclick" submit="true"
            refreshMode="partial" refreshId="myPanel">
            <xp:this.action>

                <xp:actionGroup>
                    <xp:saveDocument var="document1"></xp:saveDocument>
                    <xp:executeScript>
                        <xp:this.script>
                            <![CDATA[#{javascript:
                                var panel = getComponent("myPanel");
                                var ds = new com.ibm.xsp.model.domino.DominoDocumentData();
                                ds.setComponent(panel);
                                ds.setVar("document1");
                                panel.getData().clear();
                                panel.addData(ds);
                            }]]>
                        </xp:this.script>
                    </xp:executeScript>
                </xp:actionGroup>
            </xp:this.action>
        </xp:eventHandler>
    </xp:button>
</xp:panel>

Hope this helps

Sven

EDIT:

Added a clear() to remove all previous defined datasources from the panel.



回答2:

That's default behaviour. If you don't want to reload the whole page one option is to get rid of the datasource and create the new doc in SSJS event when Save button is clicked.



回答3:

I used Sven's answer succesfully, however, I had to add an extra line in ths server side JavaScript

<xp:executeScript>
    <xp:this.script>
        <![CDATA[#{javascript:
            var panel = getComponent("myPanel");
            var ds = new com.ibm.xsp.model.domino.DominoDocumentData();
            ds.setComponent(panel);
            ds.setVar("document1");
            ds.setFormName('form1');
            panel.getData().clear();
            panel.addData(ds);
            }]]>
    </xp:this.script>
</xp:executeScript>