I have been plagued with an issue for the past few days that I cannot solve. I am using Mojarra 2.2.12
on Wildfly 10
.
My problem is that when I use an f:ajax
tag inside of an h:inputFile
tag and attempt to re-render any component, using either the component's ID, @form
, @all
, or anything else, nothing is re-rendered. Ever. However, it works absolutely fine within an h:commandButton
or other components.
Here is a simple example.
I have an xhtml
file called index.xhtml
. This file contains an h:message
, h:inputFile
, and h:commandButton
.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:f="http://xmlns.jcp.org/jsf/core">
<h:head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</h:head>
<h:body>
<h:form id="test" enctype="multipart/form-data">
<h:message for="test" />
<br />
<h:inputFile value="#{uploadController.uploadedFile}">
<f:ajax render=":test" />
</h:inputFile>
<h:commandButton value="Push me!"
action="#{uploadController.buttonPushed}">
<f:ajax render=":test" />
</h:commandButton>
</h:form>
</h:body>
</html>
I also have a ManagedBean
class called UploadController
, which logs messages upon an action taking place, and is supposed to display a message inside of the h:message
tag once the form is re-rendered.
@ManagedBean
@ViewScoped
public class UploadController {
private Part uploadedFile;
public Part getUploadedFile() {
return uploadedFile;
}
public void setUploadedFile(Part uploadedFile) {
this.uploadedFile = uploadedFile;
System.out.println("File Uploaded!");
FacesContext.getCurrentInstance().addMessage("test", new FacesMessage("File Uploaded!"));
}
public void buttonPushed()
{
System.out.println("Button pushed!");
FacesContext.getCurrentInstance().addMessage("test", new FacesMessage("Button Pushed!"));
}
}
The expected result is that when you select a file, it will "upload" the file and then display "File Uploaded!" in the h:message
once the ajax re-renders the page. Then if you push the button, it will display "Button Pushed!" in that same h:message
.
The actual result is that, yes, "File Uploaded." is printed to the console, but the page never re-renders and the message never appears. The button, on the other hand, works perfectly, and the message appears just like it should.
I have absolutely no idea what to do from here. I'm a beginner to JSF. Why does the ajax not re-render inside the h:inputFile
, but it works perfectly fine in the h:commandButton
? Is this a bug? How can I achieve the desired results without refreshing the page?