0
In a form I have the field where I enter the name and create a folder with that name, in the second form a selectedOneMenu where lists the folders I created in the first form, now my problem is in the upload form because when I select a folder in selectedOneMenu and click to upload the file, it is not uploading, the variable where I store the folder name is getting null, down to my class who does these operations and the form if anyone can help I am grateful:
<div class="f2">
    <label class="fname">
        <h:form>
            <center>
                <label class="fname">
                    Criar Pasta de Upload:  <h:inputText value="#{upload_file.pasta}"/>
                    <p:commandButton value="SALVAR" class="btnSalvar" action="#{upload_file.criarDiretorioMacro()}" onclick="#"/>
                    Selecionar Pasta Para Upload:   
                    <h:selectOneMenu id="para" value="#{upload_file.destino}"  style="width: 100px" >
                    <f:selectItem itemLabel="selecione" itemValue=""/>
                        <f:selectItems value="#{dir_controle.selectedDs()}"  />
                    </h:selectOneMenu>
                </label>
            </center>
        </h:form>
        <h:form class="upload" >
            <p:fileUpload fileUploadListener="#{upload_file.handleFileUpload}" mode="advanced" dragDropSupport="false"
                          multiple="true" update="messages" sizeLimit="100000" fileLimit="100" allowTypes="/(\.|\/#_)(gif|jpe?g|png|bat|rar)$/"
                          />
            <p:growl id="messages" showDetail="true" />
        </h:form>
        <br></br>
    </label>
</div>
Class FileUploadView:
public class FileUploadView {
    private String arquivo;
    private String pasta;
    private String destino;
    public String getArquivo() {return arquivo;}
    public void setArquivo(String arquivo) {this.arquivo = arquivo;}
    public String getPasta() {return pasta;}
    public void setPasta(String pasta) {this.pasta = pasta;}
    public String getDestino() {return destino;}
    public void setDestino(String destino) {this.destino = destino;}
    public void criarDiretorioMacro() throws SQLException {
        DirControle dir = new DirControle();
        String directory = dir.selectedDir_CB().toString().replace("[", "").replace("]", "");
        try {
            File diretorio = new File(directory+"//"+getPasta());
            diretorio.mkdir();
        } catch (Exception ex) {
        }
    }
    public void handleFileUpload(FileUploadEvent event) throws SQLException {
        DirControle dir = new DirControle();
        String directory = dir.selectedDir_CB().toString().replace("[", "").replace("]", "");
        try {
            byte[] arquivo = event.getFile().getContents();
            String caminho = directory +"\\"+getDestino()+ "\\" + event.getFile().getFileName();
            try ( // esse trecho grava o arquivo no diretório
                    FileOutputStream fos = new FileOutputStream(caminho)) {
                fos.write(arquivo);
                FacesMessage message = new FacesMessage("Succesful", event.getFile().getFileName() + " is uploaded.");
                FacesContext.getCurrentInstance().addMessage(null, message); // mensagem pra saber se ouve sucesso
            }
        } catch (Exception ex) {
            ex.printStackTrace();
            System.out.println(ex);
        }
    }
}
Have you tried to use ajax and update the
form?– Macario1983
How do I update the form? I have used before to update another selectedOneMenu for example those of city state, but never to update the form, could you give me an example? Because I think that’s where the problem is but I don’t know how to treat
– Renato Valadao
Dude, look at the page on
Primafacesthe examples, but vc goes in the components q vc triggers the action update the whole form.– Macario1983