我正在開發一個遷移程序,它將數據從sybase傳輸到grails中的postgresql。在後端,一個grails遷移服務正在專用線程中運行。在前端,我想要顯示grails服務需要多少數據和多少時間。 在這一刻,我只能手動刷新gsp頁面,以便當前時間可以在gsp頁面上顯示數據的數量。但是,一個好主意是通過ajax定時器自動刷新gsp頁面。我嘗試在HTML上使用setInterval或setTimeOut,但它根本不起作用。 以下是我的Grails控制器和相應的視圖Grails Ajax Timer
def migrateSchuldner() {
def isRunning = personMigrationThreadService.isRunning() // boolean is the Service is running
def results = MigrationRun.findAllByEndDateIsNull()
def threadInfo
if (results.empty) {
def runCounter = personMigrationService.lastRun()
threadInfo = MigrationRun.findByCounter(runCounter) // threadInfo contains the Date and processedData and ErrorData
}
else {
threadInfo = results.get(0)
}
render view: 'migrateSchuldner', model: [threadInfo: threadInfo, isRunning: isRunning]
}
相應的觀點是:
<%@ page import="de.rvgmbh.nemesis.domain.security.Role" %>
<sec:ifAnyGranted roles="ROLE_ADMIN,ROLE_MIGRATION">
<g:applyLayout name="mainSecured" params="[currentTopNavigationIndex: 'migration', currentLeftNavigationIndex: 3]">
<head>
<title>${message(code: 'page.migration.migrate.SchuldnerData.headline.show')}
</title>
</head>
<body>
<div class="span-20 rightBorder">
<h3>${message(code: "page.migration.migrate.schuldnerData.headline.show")}</h3>
</div>
<fieldset id="migration-form">
<table>
<tr><td style="background-color: transparent">
<g:if test="${isRunning}">
<legend>
${message(code: 'page.migration.migrate.SchuldnerData.migrationInProgress')}
</legend>
</g:if>
<g:else>
<g:form action="migrateSchuldnerButtonClick" method="post" useToken="true">
${message(code: 'page.migration.migrate.SchuldnerData.legend.text')}
<input type="submit"
value= ${message(code: "page.migration.migrate.SchuldnerData.submit.text")}>
</g:form>
</g:else>
<g:if test="${threadInfo}">
<g:if test="${!isRunning}">
<legend>
${message(code: 'page.migration.migrate.SchuldnerData.lastResult')}
</legend>
</g:if>
<ul>
<li>
<label>${message(code: 'page.migration.migrate.SchuldnerData.currentTime')}:</label>
<p>${threadInfo.currentRuntime}</p>
</li>
<li>
<label>${message(code: 'page.migration.migrate.SchuldnerData.processedPersons')}:</label>
<p>${threadInfo.processedPersons}</p>
</li>
<li>
<label>${message(code: 'page.migration.migrate.SchuldnerData.personErrors')}:</label>
<p>${threadInfo.personErrors}</p>
</li>
<li>
<label>${message(code: 'page.migration.migrate.SchuldnerData.processedPersonData')}:</label>
<p>${threadInfo.processedPersonData}</p>
</li>
<li>
<label>${message(code: 'page.migration.migrate.SchuldnerData.dataErrors')}:</label>
<p>${threadInfo.dataErrors}</p>
</li>
</ul>
</g:if>
</td></tr>
</table>
</fieldset>
</body>
</g:applyLayout>
的東西是可變currentRuntime,processedPersons ......總是線程內更新。我必須刷新gsp視圖以獲取當前時間和processedPersons。 有沒有人有這阿賈克斯定時器我應該使用要達到的目標
你能告訴你的Javascript代碼? – 2012-04-03 09:37:47