2013-03-12 59 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