I work with Spring Boot 2.4.5 and JSF 2.2.20.
The h:inputFile
is not working anymore since adding Spring Boot. The action method is not called, also the setter is not called.
I have written the following backing bean:
package com.dpdhl.gmppp.portal.webapp;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import javax.servlet.http.Part;
import java.io.IOException;
import java.io.Serializable;
@Component("uploadTestController")
@Scope("request")
public class UploadTestController implements Serializable {
private static final long serialVersionUID = 1L;
private Part file1;
private String message;
public String uploadFile() throws IOException {
boolean file1Success = false;
if (file1 != null && file1.getSize() > 0) {
file1Success = true;
}
if (file1Success) {
setMessage("File successfully uploaded");
} else {
setMessage("Error, select atleast one file!");
}
return null;
}
public Part getFile1() {
return file1;
}
public void setFile1(Part file1) {
this.file1 = file1;
}
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
}
and this view:
<h2>Select and upload a file</h2>
<p>
<h:outputText value="#{uploadTestController.message}"
rendered="#{!empty uploadTestController.message}"></h:outputText>
<h:form prependid="false" enctype="multipart/form-data">
<h:panelGrid>
<h:inputFile value="#{uploadTestController.file1}"></h:inputFile>
<h:commandButton action="#{uploadTestController.uploadFile()}"
value="Upload"></h:commandButton>
</h:panelGrid>
</h:form>
</p>
If I use JSF without Spring Boot, then it works.
Can anyone help me here?