I have a form in JSF 2.2:
<h:form enctype="multipart/form-data">
<h:outputLabel>title *</h:outputLabel>
<h:inputText value="#{bean.title}" required="" />
<h:outputLabel>Image *</h:outputLabel>
<h:inputFile value="#{bean.picutreFile}" a:accept="image/*">
<f:ajax listener="#{bean.uploadPicture}" />
</h:inputFile>
<h:commandLink action="#{bean.save}">
Save
</h:commandLink>
</h:form>
The functions:
public String save() {
return "/index?faces-redirect=true";
}
public void uploadPicture() {
// Do nothing
}
But after I choose an image and get the call of uploadPicture function, the save function can't redirect the page. It calls to save but the redirect is not working, and just refresh the current page.
If I skip the file upload, it redirects normally. How can I make it to work?
EDIT
I have noticed that if I remove the ajax <f:ajax listener="#{bean.uploadPicture}" /> it works as expected. But I must to have that ajax because I want to display the image after upload.
EDIT 2
I can see that after the ajax called, the JSF creates a weird iframe at the bottom of the page with partial-response tag in it's body, and when I press 'Save` that iframe is redirects to the destination. Why is that??