Combo Box Filler via SelectItems (Java)

	//begin comboList Items grab
	public List<SelectItem> getSelectItems() throws IOException {

		//set up empty placeholder list Items
		List<SelectItem> selectItems = new ArrayList<SelectItem>();

		//Directory where files reside
		File localDir = new File("C:\\temp\\WEB_FILES");
		//local variable statement
		FilenameFilter filterDir = new FilenameFilter() {
			public boolean accept(File localDir, String fileName) {
				return fileName.startsWith("JFreeChartCSVData");
		//plug matching files into String array
		String[] localFiles = localDir.list(filterDir);
		//ensure directory actually contains fileNames startsWith("JFreeChartCSVData")
		if (localFiles == null) {
					.println("Files not found, please check directory listings");
		//loop through directory if it actually contains fileNames startsWith("JFreeChartCSVData")
		} else {

			//enter loop, grab all matching files
			for (int i = 0; i < localFiles.length; i++) {
				//load matching files to comboBox variable
				String cboFiles = localFiles[i];

				//set up files into selection comboList
				selectItems.add(new SelectItem(localDir + "\\" + cboFiles.toString()));
		//List localFiles found
		return selectItems;

Use this XSnippet in your Xpages form to load a list obtained from your C\ Drive, having a list of specific files similar in name, into a combo box on that form...  Not a lot of testing was done but it does the trick, please give it a go; Xpages form that compliments this sample being added momentarily.

Köll S Cherizard
January 23, 2013 12:32 AM

All code submitted to OpenNTF XSnippets, whether submitted as a "Snippet" or in the body of a Comment, is provided under the Apache License Version 2.0. See Terms of Use for full details.

No comments yetLogin first to comment...