Search code examples
javahtmljira-rest-java-api

Convert List from java to a dropdown menu in html


I have output from a java code in the form of a list

public class getProjectList {
    final String username = "username";
    final String password = "password";
    final String ProjectNames = null;

    public getProjectList() throws URISyntaxException, InterruptedException, ExecutionException {
        final URI jiraserverURI = new URI("https://jira.xxxx.com");
        final JiraRestClientFactory restClientfactory = new AsynchronousJiraRestClientFactory();
        final JiraRestClient restClient =
          restClientfactory.createWithBasicHttpAuthentication(jiraserverURI,username,password);
        final Iterable<BasicProject> allproject = restClient.getProjectClient().getAllProjects().get();
        final String ProjectNames = allproject.toString();
        System.out.println(ProjectNames);
    }
}

I want to use the output from this code as a dropdown menu item. Need help with this. Thank You


Solution

  • String projectsToHtmlOptions(String projectNames,String separator){
       StringBuilder sb = new StringBuilder();
       sb.append("<select>");
       for(String project:projectNames.split(separator)
          sb.append("<option value=\""+project+"\">"+project+"</option>");
       sb.append("</select>");
       return sb.toString();
    }