White Space selectOneMenu

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", " , but now the selectOneMenu kind of skips a line where I had the name I gave the .replace, how do I now remove this blank line?

Below is the method I'm using to list in selectOneMenu it picks up the name of 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 which 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> 
    
asked by anonymous 05.10.2016 / 16:32

1 answer

0

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

If you need that, if the filename is completely empty, do not include it in listaFiles , just do not insert in listaFiles .

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

In the above line, you do not care about this. The correct thing would be to do something like this:

String nomeAhSerInseridoEmLista = arq.getName().replace("datasulDescargaBancos.bat","").replace(" ","");
if(!nomeAhSerInseridoEmLista.isEmpty()) {
    listaFiles.add(nomeAhSerInseridoEmLista);
}
    
05.10.2016 / 20:26