有一個數據庫,我只想要某個類別的一個文檔。所以當用戶轉到這個Xpage時,我想測試一下,看看是否已經有一個文檔,如果有的話,抓住那個,如果沒有,然後創建並保存一個。這段代碼爲什麼寫出兩個文件?
我在數據源中寫了一些SSJS來做到這一點,但是第一次運行它會創建兩個文檔。我在代碼中放置了一個打印,並且它執行了這個部分兩次。它爲什麼這樣做?
<?xml version="1.0" encoding="UTF-8"?>
<xp:view xmlns:xp="http://www.ibm.com/xsp/core"
xmlns:xe="http://www.ibm.com/xsp/coreex">
<xp:this.beforePageLoad><![CDATA[#{javascript:sessionScope.selectedPage = "page001"}]]></xp:this.beforePageLoad>
<xp:this.resources>
<xp:script src="/xpValidationDocument.jss" clientSide="false" />
<xp:styleSheet href="/custom.css" />
</xp:this.resources>
<xp:this.data>
<xp:dominoDocument var="document1" action="editDocument">
<xp:this.documentId><![CDATA[#{javascript:sessionScope.selectedPage = "page001";
var v:NotesView = database.getView(sessionScope.selectedPage)
var doc:NotesDocuent = v.getFirstDocument()
if (doc == null)
{doc = database.createDocument();
doc.appendItemValue("form","document");
doc.appendItemValue("key",sessionScope.selectedPage);
doc.appendItemValue("crtUsr",session.getCommonUserName());
doc.appendItemValue("crtDte",session.evaluate('@Today'))
doc.save();
print ("here");
return doc.getUniversalID();}
else
{
print ("here2");
return doc.getUniversalID()}}]]></xp:this.documentId>
</xp:dominoDocument>
</xp:this.data>
<xp:panel style="width:900.00px" id="pnlForm">
<xe:widgetContainer id="widgetContainerHeader"
style="width:100%">
<xp:panel id="plContainer">
<xe:formTable id="frLocationMaster"
disableErrorSummary="true" disableRowError="true"
style="lotusForm2" styleClass="scllotusui30dojo">
<xp:this.facets />
<xe:formRow id="formRow5" labelPosition="none"
style="padding-bottom:10.0px">
<xp:table style="width:99%" border="0"
cellpadding="0" role="presentation" cellspacing="0"
id="table2">
<xp:tr>
<xp:td
style="width:80.00px;min-width:120px">
<xp:label id="label2" for="formRow1"
value="Notes" />
</xp:td>
<xp:td style="width:px">
<xp:inputRichText
id="inputRichText1" value="#{document1.Body}">
<xp:this.attrs>
<xp:attr name="toolbar">
<xp:this.value><![CDATA[
[
["Format", "Font", "FontSize"],
["Bold", "Italic", "Underline", "Strike", "-", "TextColor", "BGColor", "-", "JustifyLeft", "JustifyCenter", "JustifyRight", "JustifyBlock", "NumberedList", "-", "BulletedList"],
["Indent", "Outdent"],
["Subscript", "Superscript"],
["RemoveFormat", "-", "MenuPaste", "-", "Undo", "Redo", "Find", "LotusSpellChecker", "-", "Image", "Table", "Link", "Flash", "-", "PageBreak", "HorizontalRule", "SpecialChar", "Blockquote", "Smiley", "ShowBlocks"],
["Maximize", "Source"]
]
]]></xp:this.value>
</xp:attr>
</xp:this.attrs>
<xp:this.dojoAttributes>
<xp:dojoAttribute
name="enterMode" value="2" />
</xp:this.dojoAttributes>
</xp:inputRichText>
</xp:td>
</xp:tr>
</xp:table>
</xe:formRow>
</xe:formTable>
</xp:panel>
</xe:widgetContainer>
</xp:panel>
</xp:view>
由於請求處理生命週期。嘗試通過用$替換#來使得在負載上計算的documentId屬性。 –