xPage with multiple datasources has the second dat

2019-01-26 18:54发布

问题:

I have an xPage with 2 datasources. I open the page and the first datasource is readonly, while the second datasource is in edit mode. Adding ignoreRequestParms=true seems to cause this behavior, but its the only way that the document will save to a different datasource.

I have found this link that someone has found similar behavior. http://www-10.lotus.com/ldd/nd85forum.nsf/7756aedc25e6d81285256324005ac76c/5e2f855ea18ff802852576e3007c34f2?OpenDocument

There is something going on that I don't understand. If someone could explain this to me I would appreciate it.

Here is the code for the data source and the fields in the tab panel

<xp:dominoDocument var="document2" action="createDocument"
        formName="software" ignoreRequestParams="true">
    </xp:dominoDocument>

<xp:tabbedPanel id="tabbedPanel1">
    <xp:tabPanel id="tabPanel1" label="Checklist Items">
        <xp:checkBoxGroup id="checkBoxGroup1" layout="pageDirection"
            value="#{document1.checklist}">
            <xp:selectItems>
                <xp:this.value><![CDATA[#{javascript:var dbName = new     Array("","");
var Rep = @Unique(@DbColumn(dbName,"checklistitems",3));
Rep}]]></xp:this.value>
            </xp:selectItems>
        </xp:checkBoxGroup>
    </xp:tabPanel>
    <xp:tabPanel label="Software" id="tabPanel2">



        <xp:button value="Edit Software list" id="button1">

        <xp:eventHandler event="onclick" submit="true" refreshMode="partial"  refreshId="panelsoft">
            <xp:this.action>
                <xp:changeDocumentMode mode="edit"
                    var="document2">
                </xp:changeDocumentMode>
            </xp:this.action></xp:eventHandler></xp:button>
        <xp:button value="Save Software list" id="button2">
            <xp:eventHandler event="onclick" submit="true"
                refreshMode="partial" refreshId="panelsoft">
                <xp:this.action>

                    <xp:actionGroup>



                        <xp:modifyField name="uid"
                            value="#{javascript:document1.getDocument().getUniversalID()}"
                            var="document2">
                        </xp:modifyField>

                    <xp:executeScript script="#{javascript:document2.save()}">
                        </xp:executeScript></xp:actionGroup>
                </xp:this.action>
            </xp:eventHandler>
        </xp:button>
        <xp:br></xp:br>

        <xp:panel id="panelsoft"><xp:table rendered="#{javascript:document2.isEditable()}"><xp:tr><xp:td><xp:br></xp:br>
                    Software Name
                </xp:td>
                <xp:td>
                    <xp:inputText id="inputText1"
                        style="width:300px" value="#{document2.Softwarename}">
                    </xp:inputText></xp:td>
            </xp:tr>
            <xp:tr>
                <xp:td></xp:td>
                <xp:td></xp:td>
            </xp:tr>
        </xp:table>
        <xp:viewPanel rows="30" id="viewPanel1">
            <xp:this.facets>
                <xp:pager partialRefresh="true"
                    layout="Previous Group Next" xp:key="headerPager" id="pager1">
                </xp:pager>
            </xp:this.facets>
            <xp:this.data>
                <xp:dominoView var="view2" viewName="CustomSoftware"
                    categoryFilter="#{javascript:document1.getDocument().getUniversalID()}">
                </xp:dominoView>
            </xp:this.data>
            <xp:viewColumn columnName="uid" id="viewColumn1">
                <xp:viewColumnHeader value="uid"
                    id="viewColumnHeader1">
                </xp:viewColumnHeader>
            </xp:viewColumn>
            <xp:viewColumn columnName="Softwarename"
                id="viewColumn2">
                <xp:viewColumnHeader value="Software Name"
                    id="viewColumnHeader2">
                </xp:viewColumnHeader>
            </xp:viewColumn>
            <xp:viewColumn columnName="comments" id="viewColumn3">
                <xp:viewColumnHeader value="Comments"
                    id="viewColumnHeader3">
                </xp:viewColumnHeader>
            </xp:viewColumn>
        </xp:viewPanel>

        </xp:panel>

        <xp:br></xp:br>
        <xp:br></xp:br>
        <xp:br></xp:br>

        <xp:br></xp:br>



        <xp:br></xp:br>




        <xp:br></xp:br>

        <xp:panel>

        </xp:panel>
        <xp:br></xp:br>
    </xp:tabPanel>
</xp:tabbedPanel>

回答1:

Because action is set to createDocument (which you could omit, since that's the default value), this causes a new document to be created in memory. This is why the document is in edit mode: you're composing a new record. If you don't want to create a new document, then change the action attribute to one of the other options: openDocument or editDocument. Either of these require that the documentId attribute be set as well, because the data source needs to know which document you wish to, respectively, open or edit.

If you omit the ignoreRequestParams attribute, then this data source doesn't ignore the URL request parameters. Instead, it looks for parameters named databaseName, formName, documentId, and action. If any of these parameters are included in the URL, the value of each overrides what is defined on the data source. This is why if you open an instance of document1, but don't set ignoreRequestParams on document2, then both documents will have the same mode (read/edit): because neither data source is ignoring the URL, so both data sources are doing what the URL is telling them to.

Generally, when defining multiple data sources on the same XPage, you'll have one that can be considered the "primary" data source; any other data has some relationship to that data, but the primary data is the user's context for viewing all the data on that page. So you want that data source to respect URL parameters to allow navigation (from a Data View, View Panel, Repeat, etc.) to be able to indicate which document is being opened, and in what mode. But all data sources related to that document should explicitly specify what data they're bound to, and the action being taken on that data, and use ignoreRequestParams to ensure that the URL doesn't override this information.



标签: xpages