Vaadin 8 RadioButtonGroup Rendering error

Hi all,

We have a dynamic form that will change the information and options shown to the user depending on the selection of items that the user decides to choose.

As per our first example the 3.6 question will enable the 4.1 question.

![Example 1]
(https://i.imgur.com/N2PTcEA.png)

If the user selects the option “low” in the 4.1 question…

![Example 2]
(https://i.imgur.com/ujRC49B.png)

And the user then selects the “no” option in the 3.6 question…

![Example 3]
(https://i.imgur.com/0FxFgVV.png)

And then the user selects “yes” again in the 3.6 question…

![Example 4]
(https://i.imgur.com/9bKlnne.png)

Then there’s this really odd behavior:
As you can see, in the last image, the last 2 options, “low” and “very low”, are missing.
We suspect that is possible that it’s related to the previously checked option.

For example: If we select “low” in the 4.1 question and then we disable the option in 3.6 selection “no” and we enable it again, with the “yes” option in the 3.6 question, then everything in the 4.1 possible responses is missing from the “low” checkbox to the right.

What makes this even more odd is that before making the 4.1 question visible again we make a .clear in the radiobutton

	public void executeDelta(RiskCalculatorDeltaPresenter rcDelta) {
		List<RiskCalculatorSectionPresenter> lsSections = rcDelta.getSections();
		lsSections.forEach(item -> executeDeltaSection(item));
	}
	
	public void executeDeltaSection(RiskCalculatorSectionPresenter section) {
		String sectionId = section.getId();
		VerticalLayout vl = (VerticalLayout) GeneralUtils.findComponentById(vlRiskCalculatorSections, sectionId);
		if(section.isEnabled()) {
			section.getQuestions().forEach(item -> executeQuestionDelta(item, vl));
		} else {
			section.getQuestions().forEach(item -> executeDeselectAnswers(item, vl));
		}
		vl.setVisible(section.isEnabled());
	}
	
	public void executeQuestionDelta(RiskCalculatorQuestionPresenter question, VerticalLayout vlSection) {
		String questionId = question.getId();
		VerticalLayout vl = (VerticalLayout) GeneralUtils.findComponentById(vlSection, questionId);
		if(question.isEnabled()) {
			question.getAnswerBlocks().forEach(item -> executeAnswerBlockDelta(item, vl));
		} else {
			executeDeselectAnswers(question, vlSection);
		}
		vl.setVisible(question.isEnabled());
	}
	
	private void executeAnswerBlockDelta(RiskCalculatorAnswerBlockPresenter answerBlock, VerticalLayout vlQuestion) {
		String answerBlockId = answerBlock.getId();
		Object answerGroup = GeneralUtils.findComponentById(vlQuestion, answerBlockId);
		DataProvider dp = null;
		if(answerGroup instanceof RadioButtonGroup) {
			RadioButtonGroup<RiskCalculatorAnswerPresenter> rbg = (RadioButtonGroup<RiskCalculatorAnswerPresenter>) answerGroup;
			rbg.setEnabled(answerBlock.isEnabled());
			if(answerBlock.isEnabled()) {
				answerBlock.getAnswers().forEach(item -> executeAnswerDelta(item, rbg));
			}
			dp = rbg.getDataProvider();
		} else {
			CheckBoxGroup<RiskCalculatorAnswerPresenter> cbg = (CheckBoxGroup<RiskCalculatorAnswerPresenter>) answerGroup;
			cbg.setEnabled(answerBlock.isEnabled());
			if(answerBlock.isEnabled()) {
				answerBlock.getAnswers().forEach(item -> executeAnswerDelta(item, cbg));
			}
			dp = cbg.getDataProvider();
		}
		dp.refreshAll();
	}
	
	private void executeAnswerDelta (RiskCalculatorAnswerPresenter answer, Object group) {
		String answerId = answer.getId();
		
		Boolean selected = false;
		RiskCalculatorAnswerPresenter selectedItem = null;
		
		if(group instanceof RadioButtonGroup) {
			RadioButtonGroup<RiskCalculatorAnswerPresenter> rbg = (RadioButtonGroup<RiskCalculatorAnswerPresenter>) group;
			ListDataProvider<RiskCalculatorAnswerPresenter> dp = (ListDataProvider<RiskCalculatorAnswerPresenter>) rbg.getDataProvider();
			for(RiskCalculatorAnswerPresenter rcap : dp.getItems()) {
				if(rcap.getId().equals(answerId)) {
					rcap.setEnabled(answer.isEnabled());
					rcap.setSelected(answer.isSelected());
					if(answer.isSelected()) {
						selected = true;
						selectedItem = rcap;
					}
				}
			}
			try {
				if(selected) {
					rbg.setSelectedItem(selectedItem);
				}
			} catch(Exception e) {
				e.printStackTrace();
			}
			rbg.setItemEnabledProvider(item -> item.isEnabled());
		} else {
			CheckBoxGroup<RiskCalculatorAnswerPresenter> cbg = (CheckBoxGroup<RiskCalculatorAnswerPresenter>) group;
			ListDataProvider<RiskCalculatorAnswerPresenter> dp = (ListDataProvider<RiskCalculatorAnswerPresenter>) cbg.getDataProvider();
			
			for(RiskCalculatorAnswerPresenter rcap : dp.getItems()) {
				if(rcap.getId().equals(answerId)) {
					rcap.setEnabled(answer.isEnabled());
					rcap.setSelected(answer.isSelected());
					if(answer.isSelected()) {
						cbg.select(rcap);
					}
				}
			}
			cbg.setItemEnabledProvider(item -> item.isEnabled());
		}
	}
	
	public void executeDeselectAnswers(RiskCalculatorQuestionPresenter question, VerticalLayout vlQuestion) {
		question.getAnswerBlocks().forEach(answerBlock -> {
			String answerBlockId = answerBlock.getId();
			Object answerGroup = GeneralUtils.findComponentById(vlQuestion, answerBlockId);
			if(answerGroup instanceof RadioButtonGroup) {
				RadioButtonGroup rbg = (RadioButtonGroup) answerGroup;
				rbg.clear();
			} else {
				CheckBoxGroup cbg = (CheckBoxGroup) answerGroup;
				cbg.clear();
			}
		});
	}

If we never hide the question in the code leaving setvisible to true the issue won’t reproduce.

Debugging shows that all the responses are there in the data provider even tough they are not rendered

So, basically we don’t understand why the question is being lost in the render.

Any help would be apreciated