2012-08-30 49 views
0

我有一個重複控件,它在特定視圖中顯示文檔。對於每個文檔(數據行),用戶可以編輯並保存這些內容。我有一個額外的按鈕,它將單個文檔標記爲默認文檔,只有在編輯模式下才可以看到它,在它將當前文檔標記爲默認文檔之前,它會通過所有其他文檔並取消將它們標記爲默認文檔。此標記默認爲第一次,但當我再次嘗試時(第二次),它會創建複製衝突。XPage在視圖中內聯編輯文檔並在保存後關閉文檔

編輯按鈕即可更改爲編輯模式的模式。

保存執行以下操作(局部刷新):

<xp:this.action> 
    <xp:actionGroup> 
     <xp:saveDocument var="deliveryDocument"></xp:saveDocument> 
     <xp:changeDocumentMode mode="readOnly" 
      var="deliveryDocument"> 
     </xp:changeDocumentMode> 
    </xp:actionGroup> 
</xp:this.action> 

設置默認執行以下操作(刷新):

<xp:this.action> 
    <xp:actionGroup> 
     <xp:executeScript 
      script="#{javascript:markAsDefault(deliveryDocument);}"> 

     </xp:executeScript> 
     <xp:saveDocument var="deliveryDocument"></xp:saveDocument> 
     <xp:changeDocumentMode mode="readOnly" 
      var="deliveryDocument"> 
     </xp:changeDocumentMode> 
    </xp:actionGroup> 
</xp:this.action> 

markAsDefault首先通過現有的所有交付的文件和置頂ISDEFAULT (當前文檔除外),然後爲當前文檔設置isDefault值(它不保存後端文檔,循環執行doc.recycle())。

任何幫助,將不勝感激。

更新:

function markAsDefault(deliveryDoc) { 
    try { 
     var db:NotesDatabase = deliveryDoc.getParentDatabase(); 
     var vwDeliveryAddress:NotesView = db.getView("viewName"); 

     var dc:NotesDocumentCollection = vwDeliveryAddress.getAllDocumentsByKey(deliveryDoc.getItemValueString("fldID"), true); 

     var strUniversalID:String; 

     strUniversalID = deliveryDoc.getDocument().getUniversalID(); 

     if (dc.getCount() > 0) { 
      var doc:NotesDocument = dc.getFirstDocument() 
      var nextDoc:NotesDocument; 

      // mark all other docs as not default 
      while (doc != null) { 
       nextDoc = dc.getNextDocument(); 

       if (doc.getUniversalID() != strUniversalID) { 
        doc.replaceItemValue("isDefault", ""); 
        doc.save(); 

        doc.recycle(); 
       } 

       doc = nextDoc; 
      } 
     } 

     deliveryDoc.replaceItemValue("isDefault", "Yes"); 
    } catch (e) { 
     log.logError(e.toString(), SEVERITY_HIGH, e.toString(), null, "website.nsf", "markAsDefault()", null, null); 
    } 
} 
+0

後markAsDefaut()代碼,請。調用getDocument()可能會導致衝突。 –

+0

發佈 - 謝謝。 – pipalia

+0

字符串比較似乎對我很腥。 http://stackoverflow.com/questions/513832/how-do-i-compare-strings-in-java –

回答

2

我認爲保存衝突的原因是因爲你用相同的文件在內存中處理(在XPage中),並在磁盤上。內存文檔的時間戳記在保存在磁盤文檔之前,因此在保存內存文檔時存在衝突。

如果你不介意的東西覆蓋彼此沒有衝突,可以設置以防止保存衝突形式的屬性。在表單屬性中的第一個選項卡上:衝突處理 - 不要創建衝突

來解決此問題不設置該屬性的最簡單的方法是隻擁有一個文檔時可編輯。有一個viewScope變量,它包含當前可編輯文檔的單元。根據此屬性設置呈現的表單。將字段綁定到requestScope,其中默認值來自文檔。當用戶點擊保存時,通過requestScope值的單一/更新來查找文檔。這樣,你只能處理磁盤上的文件。

編輯 - 示例代碼:

<?xml version="1.0" encoding="UTF-8"?> 
<xp:view xmlns:xp="http://www.ibm.com/xsp/core"> 
    <xp:this.data> 
     <xp:dominoView var="peopleView" viewName="People"></xp:dominoView> 
    </xp:this.data> 
    <xp:table id="peopleTable"> 
     <xp:repeat id="peopleRepeat" rows="30" value="#{peopleView}" var="personRow"> 
      <xp:panel rendered="#{javascript:return (viewScope.editableUnid === personRow.getUniversalID());}" 
       tagName="tr"> 
       <td> 
        <xp:inputText value="#{requestScope.firstName}" defaultValue="#{personRow.first_name}" /> 
       </td> 
       <td> 
        <xp:inputText value="#{requestScope.lastName}" defaultValue="#{personRow.last_name}" /> 
       </td> 
       <td> 
        <xp:button id="saveButton" value="Save"> 
         <xp:eventHandler event="onclick" submit="true" refreshMode="partial" refreshId="peopleTable"> 
          <xp:this.action><![CDATA[#{javascript:var doc = database.getDocumentByUNID(viewScope.editableUnid); 
doc.replaceItemValue('first_name', requestScope.firstName); 
doc.replaceItemValue('last_name', requestScope.lastName); 
doc.save(); 
viewScope.editableUnid = null;}]]></xp:this.action> 
         </xp:eventHandler> 
        </xp:button> 
        <xp:button id="cancelButton" value="Cancel"> 
         <xp:eventHandler event="onclick" submit="true" refreshMode="partial" refreshId="peopleTable"> 
          <xp:this.action><![CDATA[#{javascript:viewScope.editableUnid = null;}]]></xp:this.action> 
         </xp:eventHandler> 
        </xp:button> 
       </td> 
      </xp:panel> 
      <xp:panel rendered="#{javascript:return (viewScope.editableUnid != personRow.getUniversalID());}" tagName="tr"> 
       <td> 
        <xp:text value="#{personRow.first_name}" /> 
       </td> 
       <td> 
        <xp:text value="#{personRow.last_name}" /> 
       </td> 
       <td> 
        <xp:button id="editButton" value="Edit"> 
         <xp:eventHandler event="onclick" submit="true" refreshMode="partial" refreshId="peopleTable"> 
          <xp:this.action><![CDATA[#{javascript:viewScope.editableUnid = personRow.getUniversalID();}]]></xp:this.action> 
         </xp:eventHandler> 
        </xp:button> 
       </td> 
      </xp:panel> 
     </xp:repeat> 
    </xp:table> 
</xp:view> 
+0

這將如何工作重複控制?我將不得不顯示一個對話框來修改每個文檔,或者它會像當前一樣工作嗎? – pipalia

+0

如果將重複控件綁定到視圖,請在計算字段中顯示值。在重複中也包含相同的字段。您可以將視圖值用作表單字段的默認值。可以從行var獲取文檔的單引號。這樣可以獲得良好的性能/小內存使用量,因爲這些值是從視圖中讀取的。 當「編輯」 UNID是一樣的一排,隱藏計算領域+編輯控件,並顯示窗體域+節能控制。 –

+0

會給一個去和你保持聯絡 - 感謝湯米 – pipalia