White Space selectOneMenu

Asked

Viewed 148 times

0

I would like to know if it is possible to remove a blank field in selectOneMenu, I have the following case, I have a selectOneMenu that displays several names, some names that I do not want to appear I used . replace("name",""), only now selectOneMenu kind of skips a line where it had the name I gave the . replace, how do I now remove this blank line ?

below is the method I am using to list in selectOneMenu it takes the name of the files that are in a directory

public ArrayList<String> SearchFileStop (String p) throws SQLException{

    DirControle dc = new DirControle();
    File file = new File(String.valueOf(dc.selectedDir_CB()).replace("[", "").replace("]","")+"\\"+p);
       File afile[] = file.listFiles();
       int i = 0;
       for (int j = afile.length; i< j; i++){
           File arq = afile[i];

          listaFiles.add(arq.getName().replace("datasulDescargaBancos.bat","").replace(" ",""));
       }

       return listaFiles;
    }

my bean

public ArrayList<String> selectedFile(String arq) throws SQLException{return sdir.SearchFile(arq);} 

The Selectonemenu, in this case the problem is in the second:

  To:  

                                <f:selectItem itemLabel="selecione" itemValue=""/>
                                <f:selectItems value="#{dir_controle.selectedDs()}"  />
                                <p:ajax listener="#{scripts.listener}" update="arquivo" /> 

                            </h:selectOneMenu>

                            &nbsp;&nbsp;<label class="title4">Banco:</label>&nbsp;&nbsp;
                            <h:selectOneMenu id="arquivo" value="#{scripts.arquivo}" style="width: 200px">
                                <f:selectItem itemLabel="Selecione"/> 
                                <f:selectItems  value="#{dir_controle.selectedFile(scripts.pasta)}" />

                            </h:selectOneMenu> 
  • Is the data coming from the bank? To help you better, I suggest you post the codes you are using.

  • Edit your question and post the code on it, it’s more readable please.

  • edited see if it’s clearer now

  • Also post your xhtml page.

  • posted I hope it’s clearer

1 answer

0

Friend, the problem is not in jsf, but in its logic to the popular the list of String.

If you need the file name to be completely empty, do not include it in listaFiles, just do not insert in listaFiles.

listaFiles.add(arq.getName().replace("datasulDescargaBancos.bat","").replace(" ",""));

In the line above, you don’t care about that. The right thing would be to do something like this:

String nomeAhSerInseridoEmLista = arq.getName().replace("datasulDescargaBancos.bat","").replace(" ","");
if(!nomeAhSerInseridoEmLista.isEmpty()) {
    listaFiles.add(nomeAhSerInseridoEmLista);
}
  • I understood I did it this way and it worked, if you can get me another doubt in that same part has as I hide the whole string checking if it has a piece of a word in it, for example dataDescargaBancos.bat hide if you have Download in the word

  • Try to use nomeAhSerInseridoEmLista.contains("descarga"), maybe it works. It goes according to your logic, whether you want to include it or not in the list.

Browser other questions tagged

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