Нажатием кнопки мой ajax вызывает управляемый компонент yourFileData. В yourFileData () я создал новый поток из основного потока. Поэтому я хочу выполнить основной поток с первой попытки, и новый поток будет запущен и обновит счетчик строк, чтобы я мог динамически обновлять этот счетчик на моем модальном.
Я также создал фиктивную кнопку для обновления моего hiddenCurrentRowCount, но это не помогло мне, и я также обновляюсь каждые 5 секунд.
Код во фрагменте кода только для вашей цели, там ничего не работает.
function ajaxValidateFile(data) {
var status = data.status;
switch (status) {
case "begin":
refreshRowCount();
break;
case "complete":
break;
case "success":
openModalWindow();
break;
}
}
var refreshRowTimer;
function refreshRowCount(){
refreshRowTimer = setInterval(refreshRowCount, 5000);
$("#dummyHiddenBtn").click();
currentCount = $("#hiddenCurrentRowCount").val();
$("#validateMsg").html('<p>Validating ' + currentCount + ' of '+ totalCount + ' records </p>');
if($("#hiddenTotalRowCount").val() === $("#hiddenCurrentRowCount").val()){
clearInterval(refreshRowTimer);
$( '#dialog' ).modal( 'close' );
console.log('Here you go');
}
}
openModalWindow = function() {
totalCount = $("#hiddenTotalRowCount").val();
currentCount = $("#hiddenCurrentRowCount").val();
$("#validateMsg").html('<p> Validating ' + currentCount + ' of '+ totalCount + ' records </p>');
$( '#dialog' ).modal( 'open' );
};
I have jsf code below :
<div>
<h:commandButton id="validateFileBtn" value="Validate File" >
<f:ajax execute="uploadCsvFile" event="click" listener="#{formManagedBean.yourFileData}" render="validateFileBtn hiddenTotalRowCount dummyHiddenBtn hiddenCurrentRowCount messagesDiv :csvFilesForm" onevent="ajaxValidateFile" onerror="ajaxOnError"/>
</h:commandButton>
</div>
<h:commandButton id="formManagedBean" styleClass="dol-hide" >
<f:ajax listener="#{formManagedBean.dummyCallRefreshData}" render="hiddenCurrentRowCount"/>
</h:commandButton>
<h:inputHidden id="hiddenTotalRowCount" value="#{formManagedBean.lineCount}" rendered="#{not empty formManagedBean.lineCount}"></h:inputHidden>
<h:inputHidden id="hiddenCurrentRowCount" value="#{formManagedBean.rowNum}" rendered="#{not empty formManagedBean.rowNum}"></h:inputHidden>
public List<String> yourFileData(AjaxBehaviorEvent event) {
try {
// code running for LineCount before new thread and it works fine
Thread one = new Thread(){
public void run() {
try{
String input;
while((input = bfReaderCount.readLine()) != null){
rowNum++;
}
}catch(Exception e){
e.printStackTrace();
}
}
};
one.start();
System.out.println("Does it work NOOOOOOO?");
} catch (Exception e){
e.printStackTrace();
}
return someList;
}