List the directory names of a given location in a selectOneMenu

Asked

Viewed 122 times

1

Hello, I am with this doubt, I already managed to list the directories with methods found on the internet, but I could not implement in a method that feeds a <h:selectOneMenu> to select an item. Any suggestions/solutions? Thank you.

To list the directories:

private String selectItem;
private List<SelectItem> siglas;

@PostConstruct
public void init() {
    this.modulo = new Modulo();
    getAllModulos();

    /* Listagem de diretórios para popular o SelectOneMenu */
    siglas = new ArrayList<SelectItem>();

    File directory = new File(".");

    File[] subdirs = directory.listFiles((FileFilter) DirectoryFileFilter.DIRECTORY);
    for (File dir : subdirs) {
        siglas.add(new SelectItem(dir.getName(), dir.getName().toUpperCase()));
    } /* fim da listagem de diretórios */
}

Running this method on a main, it shows the structure of the application, but when running on Tomcat, it only shows the structure of the operating system.

Selectonemenu

<h:selectOneMenu id="siglas" value="#{moduloBean.modulo.sigla}" label="Siglas">
    <f:selectItem itemLabel="Selecione..." noSelectionOption="true"/>
    <f:selectItems value="#{moduloBean.siglas}"/>
</h:selectOneMenu>
  • Add your xhtml, service and Entity to the post, so we can help you better.

  • updated post. @Leocbs

  • Your selectOneMenu is inside a form?

  • yes, if I put the code the way it is there, it lists, but only the directories of the Operating system, and I would like to list the directories of the application, src,main,webapps, meta-inc, web-inf. understands?

No answers

Browser other questions tagged

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