I have a problem due to server restrictions. The server allows only data under 25MB to be transmitted. The data that is supposed to be uploaded is 80MB+. I'm working with JSF, Primefaces and JavaEE. My idea was to send the data in small packages via AJAX requests. The data is split into small enough chunks, but when I click the commandButton that is supposed to execute the AJAX as often as there are chunks, it sends the first data chunk with the correct content and immediately after js clicks the button and then it only sends the content of the last chunk in every request and just after the loop is finished completely. So there is a long break between the first request and the second. I don't need them to be in order. I just want all data to arrive in the backend.
My html looks like:
<h:form> <input type="text" id="dataInput" name ="dataInput"> <h:commandButton action="#{ImportController.getTransmittedData()" id="button"> <p:ajax execute="dataInput"></p:ajax> </h:commandButton> </h:form>
And my js looks like:
startTransmittingData(){ for(let i=0; i<chunks.length(); i++){ document.getElementById("dataInput").value=chunks[i]; document.getElementById("button").click(); } }
The ImportController only takes the data.
Is it just not possible to loop over a commandButton and get an instant reaction with AJAX? It alsow seems as if it's 'stuck' somewhere. When the loop is done it starts sending the AJAX requests with the wrong content, since the input changed while looping over the chunk-List.
I tried changing the ajax but nothing made a difference.
Edit: To make the order in which the code is executed more clear:
chunks=[0,1,2,3]; i=0 button is clicked in loop and first chunk gets transmitted to ImportController. `i=1` the codeline where the button is clicked in js is called but the function ImportController is not called. `i=2` the codeline where the button is clicked in js is called but the function ImportController is not called. `i=3` the codeline where the button is clicked in js is called but the function ImportController is not called. exit loop the ImportController gets called with [3] in the input. the ImportController gets called with [3] in the input. the ImportController gets called with [3] in the input.