I'm trying to upload a file of any kind through the jsf h: inputFile element, and I try to do this with ajax, but when I try to upload this error appears in the browser console. ..
Uncaught TypeError: Cannot read property 'getAttribute' of undefined
at Object.response (jsf.js.xhtml?ln=javax.faces&stage=Development:2814)
at Object.onComplete (jsf.js.xhtml?ln=javax.faces&stage=Development:1779)
at FrameTransport.AjaxEngine.req.xmlReq.onreadystatechange (jsf.js.xhtml?ln=javax.faces&stage=Development:1760)
at FrameTransport.callback (jsf.js.xhtml?ln=javax.faces&stage=Development:367)
at HTMLIFrameElement.<anonymous> (jsf.js.xhtml?ln=javax.faces&stage=Development:400)
I'm using the following jsf libraries:
jsf-impl.2.2.15
jsf-api.2.2.15
I'm also using spring security.
The xhtml page code looks like this:
<h:inputFile value="#{imagemPerfil.arquivo}" required="true" >
</h:inputFile>
<h:commandButton
class="btn btn-primary" value="Salvar" action="#{imagemPerfil.handleFileUpload()}">
<f:ajax execute="@form" render="@form" />
</h:commandButton>
</h:form>
And the Bean:
@ManagedBean(name="imagemPerfil")
@SessionScoped
public class MudarImagemPerfil implements Serializable{
/**
*
*/
private static final long serialVersionUID = 3131478679593318664L;
private Part arquivo;
public Part getArquivo() {
return arquivo;
}
public void setArquivo(Part arquivo) {
this.arquivo = arquivo;
}
public MudarImagemPerfil() {
}
public void handleFileUpload() {
if(arquivo != null) {
System.out.println("file size: " + arquivo.getSize());
System.out.println("file type: " + arquivo.getContentType());
}else {
System.out.println("Arquivo está nulo");
}
}