0
I’m trying to upload any file by the element h:inputfile jsf itself, 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 am using the following jsf libraries:
jsf-impl.2.2.15
jsf-api.2.2.15
I’m also using spring security.
The code of the xhtml page is 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");
}
}
Actually I’m not using primefaces, what was in Bean was just a test I did and forgot to remove... I’m using pure jsf... in case your solution applies only to primefaces, but thanks for trying to help!
– Nayron Morais