2013-03-12 81 views
1

我想刷新客戶端Javascript觸發的重複控制。爲了使它有趣,我的數據源是一個JDBC查詢,這就是爲什麼我不只是進行局部刷新。 我見過有關使用XHR請求執行此操作的頁面,但我看不到如何刷新JDBC數據以捕獲新信息。 我可以使用舊數據刷新重複控制,而不是新數據。XPages - 刷新客戶端的JDBC數據

我看到了Repeat control refresh error 它談到可能需要超時,因爲運行時不知道新數據。 我手動更改數據庫中的某些內容並等待一分鐘後運行XHR,仍然有舊信息。

我可以更新RPC調用中的變量(jdbcPendingSummary)嗎?如果不能,我可以調用回服務器來觸發CSJS函數內部的刷新嗎?

<xp:this.data> 
    <xe:jdbcQuery connectionName="testDB" 
     sqlQuery="EXEC ptoGetPendingRequests #{sessionScope.userID}" 
     var="jdbcPendingSummary" /> 
</xp:this.data> 

<xe:jsonRpcService id="ptoRPC" serviceName="ptoRPC"> 
    <xe:this.methods> 
     <xe:remoteMethod name="createNewRequest"> 
      <xe:this.script><![CDATA[ 
       javaBeanObject.ptoCreateRequest(#{sessionScope.userID}, startDate, endDate, comment, d1,....,d15); 
// Can I update the datasource var here? 
      ]]></xe:this.script> 
      <xe:this.arguments> 
       <xe:remoteMethodArg name="startDate" type="string"></xe:remoteMethodArg> 
       .......... 
       <xe:remoteMethodArg name="d15" type="number"></xe:remoteMethodArg> 
      </xe:this.arguments> 
     </xe:remoteMethod> 
    </xe:this.methods> 
</xe:jsonRpcService> 

<xp:scriptBlock id="scriptBlock1"> 
    <xp:this.value><![CDATA[ 
    function createNewRequest(startDateID, endDateID, commentID, hiddenDivID, requestID) { 

     ptoRPC.createNewRequest(dojo.byId(startDateID).value, dojo.byId(endDateID).value, ........).addCallback(function(response) { 
      // ????? Refreshes the Repeat Control, but has the stale data. 
      setTimeout(
       function() { 
        XSP.partialRefreshGet(requestID, {onComplete: function(responseData) { } }) 
// Or how about updating the datasource var here? 

       }, 8000); 
     }); 
    } 
    ]]></xp:this.value> 
</xp:scriptBlock> 

回答

1

雖然這可能不是一個完美的解決方案,但向以下JDBC代碼添加scope =「request」會導致在AJAX調用完成時刷新變量。

<xp:this.data> 
    <xe:jdbcQuery connectionName="testDB" 
     sqlQuery="EXEC ptoGetPendingRequests #{sessionScope.userID}" 
     var="jdbcPendingSummary" scope="request" /> 
</xp:this.data> 
1

您可以使用特定數據源的refresh()方法實現該功能。所以,如果你有一些配置JDBC數據源查詢面板 - 然後內視圖面板中,你可以參考,並通過這樣的語法刷新數據:

getComponent(「some_panel_id_containing_your_datasource」)的getData()得到(0).REFRESH(。 );

雖然可以爲面板配置多個數據源 - 引用它們是從0索引開始的。

的代碼片段,以證明技術可能是這樣的(可能會更有意義,如果查詢將使用一些計算的參數就刷新呈現不同的數據):

<xp:panel id="outerContainer"> 
    <xp:this.data> 
     <xe:jdbcQuery var="jdbcQuery1" 
      connectionName="derby1"> 
      <xe:this.sqlQuery><![CDATA[#{javascript:"select * from users"; 
      }]]></xe:this.sqlQuery> 
     </xe:jdbcQuery> 
    </xp:this.data> 

    <xp:viewPanel rows="10" id="viewPanel1" 
     value="#{jdbcQuery1}" indexVar="idx"> 
     <xp:viewColumn id="viewColumn1" columnName="id" 
      displayAs="link"> 
      <xp:this.facets> 
       <xp:viewColumnHeader xp:key="header" 
        id="viewColumnHeader1" value="ID"> 
       </xp:viewColumnHeader> 
      </xp:this.facets> 
      <xp:eventHandler event="onclick" 
       submit="true" refreshMode="partial" refreshId="outerContainer"> 

       <xp:this.action><![CDATA[#{javascript: 
        getComponent('outerContainer').getData().get(0).refresh(); 
        }]]> 
       </xp:this.action> 
      </xp:eventHandler> 
     </xp:viewColumn> 
    </xp:viewPanel> 
</xp:panel> 
+0

我已經修改了你的榜樣,它的工作原理提取新數據 - 我無法讓PRC與您列出的數據刷新一起工作。這種方式確實會導致發送一對額外的k數據 ,但它並不可怕。 不知道怎麼回事,但在行尾有2個空格不給我一個換行符 ' ' – anotherBob 2013-03-21 17:52:08

+0

不知道我在這裏瞭解換行問題。它是在這個網站上還是在Designer內部? – andrejusc 2013-03-22 15:17:19

+0

我在評論說我無法格式化我在評論中粘貼的代碼(所以堆棧溢出,而不是設計器)。根據幫助頁面,如果您做了2個空格,它應該放入一個換行符。 – anotherBob 2013-03-22 19:59:25