On a JSF page, every handle file upload event creates a new Instance of Bean. As if it is like a new client each time. Also it seems like the web browser is a different client too.
So, Is there a way that these FileUploadEvents coming from only one browser instantiates only one Bean?
I'm trying to use CDI instead of @ViewScoped JSF bean.
index.xhtml:
<p:fileUpload fileUploadListener="#{bean.handleFileUpload}"/>
Bean:
@Named
@ConversationScoped
public class Bean {
//code
@Inject
Conversation conversation;
public void HandleFileUpload(FileUploadEvent fileUploadEvent){
if(conversation.isTransient()){ //Always true :(
conversation.begin();
}
//Beans get created each time it needs to access this method.
}
I had a misconception of @ConversationScoped.
Conversation should start before visiting a given link.
Means that if one visit a link, with no conversation started previously, the bean will act similar to a @RequestScoped bean. Therefore refreshing one page attached to a @ConversationScoped will create & destroy each time.
Solution goes to start the conversation before visiting the link, so ?cid=10 will be included in the URL.