variable does not take value from selectedOneMenu

0

In a form I have the field where I inform the name and create a folder with that name, in the second form a selectedOneMenu where I list the folders I created in the first form, now my problem is in the form of upload because when I select a folder in the selectedOneMenu and click on upload the file, it is not uploading, the variable where I store the folder name is getting null, below my class that does these operations and the form if anyone can help I'm grateful: p>

<div class="f2">
                <label class="fname">

                    <h:form>
                       <center>
                        <label class="fname">

                                Criar Pasta de Upload:&nbsp;&nbsp;<h:inputText value="#{upload_file.pasta}"/>
                                <p:commandButton value="SALVAR" class="btnSalvar" action="#{upload_file.criarDiretorioMacro()}" onclick="#"/>




                            Selecionar Pasta Para Upload:&nbsp;&nbsp; 
                            <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>

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);
    }

}

}

    
asked by anonymous 21.09.2016 / 15:20

1 answer

0

This is wrong

<f:selectItems value="#{dir_controle.selectedDs()}"  />

It should be something like this

<f:selectItems itemLabel="#{status.name}" var="status" itemValue="#{dir_controle.selectedDs()}" value="#{status}" />

More needs to be converted if working with objects

    
21.09.2016 / 15:30