variable does not take selectedOneMenu value

Asked

Viewed 43 times

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

}

}

1 answer

0

This is wrong

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

it must be something like this

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

More ai need to convert, if you are working with objects

  • So since this line of mine displays a list the value of it should not go to the value of selectedOneMenu below? On another screen I perform this procedure and it works normally <h:selectOneMenu id="to" value="#{upload_file.target}" style="width: 100px" > <f:selectItem itemLabel="select" itemValue="""/> <f:selectItems value="#{dir_control.selectedDs()}" />

Browser other questions tagged

You are not signed in. Login or sign up in order to post.