TreeTable setVisibleColumns issue

I have encountered an issue where my TreeTable (dataSource is a HierarchicalContainer) is not being shown in the application. The table has at least two properties, “section” and then one for each “facility” that a client has. The page should run the method to create the table 3 times, one for each “type”. I am assigning the first container property with a static name, but each time I run the class to create the table, there could be one or many facilities, so I have a for loop that is adding the column for each facility. When there is only one facility, the table shows without issue. Once I add a second facility, the table no longer shows.

Things I have noticed:

  • When the table does not show up:
    – The class only runs once instead of 3 times (once per “type”)
    – The comma separated list that populates the setVisibleColumns method has the correct number of properties
    – If I comment out the setVisibleColumns method the table loads, but only the first column (“section”)
    – There are no errors in the console or debug window.

Here are some key segments of the code:

dataSource = new HierarchicalContainer();
dataSource.addContainerProperty(section, String.class, null);

	table = new TreeTable();

	// Create lists of Sections and Subsections included in the WorkflowResults for this assessment
	for (WorkflowResult workflowResult : workflowResults)

		if (!facilityNames.contains(workflowResult.getFacilityName()))

			// Add a property to the dataSource for each client Facility
			dataSource.addContainerProperty(workflowResult.getFacilityName(), String.class, null);
		if (workflowResult.getSurveyType() == type)

			if (!sectionNames.contains(workflowResult.getSection()))

[/code] Followed by the code that adds the values to the columns, then…

	table.setVisibleColumns(new Object[] { section, StringUtils.join(facilityNames, ", ") });

I would think that if this wasn’t going to work, it wouldn’t work at all, but the only way it seems to fail is if there is more than one item in “facilityNames”. I know that the comma separated string is right, so I don’t think that’s the issue, so I’m thinking it has to do with how I’m adding the facility names to the dataSource. I’ve read some things about using non-standard item id’s, but I couldn’t find what the negative impact was. Is there another way I could do this, or is it obvious that I’ve gone wrong somewhere?

Thank you!

Here is the method that calls the code above. The code above is from the WorkflowResultsSection class.

		private void showWorkflowResults(List<Survey> surveys, VerticalLayout layout)

			for (Type type : Type.values())
				// Only show sections for interview questions
				if (type.ordinal() > 0 && type.ordinal() < 4)
					IDataSource source = getDataSource();
					WorkflowResultsSection component = new WorkflowResultsSection(surveys, source.getWorkflowResults(assessment), type.ordinal(), type.display());

It seems that perhaps this for loop only runs through once when there is an issue since there is only one “type” processed when there are multiple facilities and all “types” are processed when there is only one facility.

I found that there was an error, however it was not throwing it out into the console. Here is the error being reported:

java.lang.IllegalArgumentException: Ids must exist in the Container or as a generated column, missing id: Section, Main, Remote

I tried placing double quotes around each item and that did not work either. I’m baffled at why this worked without issue for a list of 2, but fails with a list of 3. Is this error indicating that the three ids are missing, or is it counting all three as one id and that’s the problem?

I feel that the issue is staring me right in the face, but I can’t determine how to apply it. Here is some more data, it is the contents of the HierarchicalContainer. I believe the issue is with the item ids in this not matching the columns listed.

PACS Admin Subsection={Remote=0.0%, Section=PACS Admin Subsection, Main=0.0%},
PACS Admin Section={Remote=0.0%, Section=PACS Admin Section, Main=0.0%}

As far as I understand, you have column (property) IDs such as “Main”, … - i.e. individual facility names. In that case, the facility names must be given as separate entries in the array, whereas your code gives an array with two strings, the latter of which contains multiple facility names and commas.

If your facilityNames only has one entry, StringUtils.join returns it as is so your code has valid column names in the Object.

Thank you, Henri! I thought that the array in the list for setVisibleColumns may have been an issue, but I wasn’t sure. Your guidance has led me quickly to a resolution.

		Object visibleColumns[] = new Object [facilityNames.size() +1]
 = section;
		for ( int i=0; i<facilityNames.size(); i++)
		System.out.println("Visible Columns are".concat(Arrays.toString(visibleColumns)));