如何在上传primefaces后重新加载jsf页面?

Kel*_*tor 5 javascript jsf file-upload primefaces jsf-2

在primefaces上传后,重新加载jsf页面有什么用?

我尝试使用javascript oncomplete="javascript:window.location.reload()",但它不起作用:

XHTML:

<h:form>
    <p:messages showDetail="true"/>  
    <p:fileUpload fileUploadListener="#{revistauploadBean.upload}"
                  mode="advanced" dragDropSupport="false" merge="true"  
                  uploadLabel="Enviar" cancelLabel="Cancelar"
                  oncomplete="javascript:window.location.reload()"
                  label="Procurar PDF" sizeLimit="1000000000" fileLimit="3"
                  allowTypes="/(\.|\/)(pdf)$/" />
</h:form>
Run Code Online (Sandbox Code Playgroud)

豆:

public void upload(FileUploadEvent event) throws SQLException {  
    LoginAuthentication user = new LoginAuthentication();
    FacesMessage msg = new FacesMessage("Success! ", event.getFile().getFileName() 
        + " is uploaded.");  
    FacesContext.getCurrentInstance().addMessage(null, msg);
    // Do what you want with the file        
    try {
        copyFile(event.getFile().getFileName(), event.getFile().getInputstream());
        ConectaBanco mysql = new ConectaBanco();
        mysql.insere("INSERT INTO edicoes VALUES (NULL, '" 
            + mysql.pegaIDrev(user.getNome()) 
            + "', NULL, NULL, NULL, NULL, '" 
            + event.getFile().getFileName()
            + "' );");
        File pasta = new File(caminhoPastaPDF 
            + "/convertidos/" 
            + event.getFile().getFileName());
        pasta.mkdir();
        convertePdf(event.getFile().getFileName());
        FacesMessage msg1 = new FacesMessage("Succesful", event.getFile().getFileName() 
            + " is uploaded.");  
        FacesContext.getCurrentInstance().addMessage(null, msg1); 
    } catch (IOException e) {
        e.printStackTrace();
    }

}  

public void copyFile(String fileName, InputStream in) {
    try {
        // write the inputStream to a FileOutputStream
        OutputStream out = new FileOutputStream(new File(destination + fileName));
        int read = 0;
        byte[] bytes = new byte[1024];
        while ((read = in.read(bytes)) != -1) {
            out.write(bytes, 0, read);
        }
        in.close();
        out.flush();
        out.close();
        ////System.out.println("New file created!");
    } 
}
Run Code Online (Sandbox Code Playgroud)

还有其他方法吗?我想刷新一个<a4j:repeat>

Xtr*_*ica 2

<p:fileUpload />有一个update属性,给定@form值后,它会再次呈现整个表单

<p:fileUpload fileUploadListener="#{fileUploadController.handleFileUpload}" 
    mode="advanced" dragDropSupport="false"  
    update="@form" sizeLimit="100000" fileLimit="3" 
    allowTypes="/(\.|\/)(gif|jpe?g|png)$/" /> 
Run Code Online (Sandbox Code Playgroud)

否则,如果您想摆脱 ajax 功能,您还可以使用基本的 fileUpload组件。

<p:fileUpload value="#{fileUploadController.file}" mode="simple"/>  

<p:commandButton value="Submit" ajax="false"  
            actionListener="#{fileUploadController.upload}"/> 
Run Code Online (Sandbox Code Playgroud)

基本上,尽量不要对已经完成的事情进行 JavaScript 处理!