I try to do a file upload in primefaces with PF 5.1 and OmniFaces version 1.7.
My .xhtml code:
p:fileUpload multiple="true"
uploads each file in its own request. Problem is, the requests happen simultaneously, which in your case triggers conversation lock timeout, since each request tries to access the same conversation. Another problem is that JSF actually requires client-side code to send requests sequentially, and its server-side code is not thread-safe.
I advise making the upload requests happen sequentially. There are multiple ways to achieve this.
PrimeFaces 5.2.6 and above: you should be able to just use the sequential
attribute:
<p:fileUpload sequential="true" ...
(The attribute was implemented in PF Issue #403.)
This answer suggests a way via Javascript, by configuring the jQuery File Upload Plugin, which PrimeFaces uses.
Add a Weld dependency. Then you could change the default lock timeout (in a non-portable CDI way), so the requests form a queue on the server. The default lock timeout is 1 second. The following code changes lock timeout globally for all conversations.
import javax.enterprise.context.ConversationScoped;
import javax.enterprise.context.Initialized;
import javax.enterprise.event.Observes;
import javax.inject.Inject;
import javax.servlet.ServletRequest;
import org.jboss.weld.context.http.HttpConversationContext;
public class ConversationTimeoutDefaultSetter {
@Inject
private HttpConversationContext ctx;
public void conversationInitialized(
@Observes @Initialized(ConversationScoped.class)
ServletRequest payload) {
ctx.setConcurrentAccessTimeout(10000L); // 10 seconds
}
}
Update: I forgot, that Initialized
requires CDI 1.1, and you seem to be using 1.0. You can set the timeout when you're begin
ning your conversation.