я хочу динамически добавить новый p:SelectOneMenu в мою панельGrid здесь
<h:panelGrid id="panel_grid" columns="1" style="margin-bottom:10px"cellpadding="5" >
<p:outputLabel for="firstQuestionDropDown" value={InsererAffaireController.firstQuestion.libeleQuestion}"
<p:selectOneMenu id="firstQuestionDropDown" value="#{InsererAffaireController.firstQuestion.libeleQuestion}" style="width:150px">
<p:ajax listener="#{InsererAffaireController.displayNextQuestion()}" update="panel_grid" />
<f:selectItems value="#{InsererAffaireController.firstQuestion.listLibeleReponses}" />
</p:selectOneMenu>
<!-- Here i want to add my new SelectOneMenu -->
</h:panelGrid>
Мне удалось сделать это из управляемого компонента, но проблема в том, что я не могу заполнить новый SelectOneMenu, и я не знаю, как добавить к нему af: selectItems, вот метод, который добавляет новый p: SelectOneMenu на панель сетка, но она все еще пуста
public void displayNextQuestion() {
nextQuestion = getNextQuestion();
OutputLabel nextQuestionLabelUI = new OutputLabel();
nextQuestionLabelUI.setValue(nextQuestion.getLibeleQuestion());
SelectOneMenu nextQuestionDropDown = new SelectOneMenu() ;
List<SelectItem> selectItems = new ArrayList<>();
for (String s : nextQuestion.getListLibeleReponses()) {
selectItems.add(new SelectItem(s, s));
System.out.println(selectItems.get(0).getLabel());
}
// How can i add the selectitems to the SelectOneMenu
UIComponent panelGrid = findComponent("panel_grid");
panelGrid.getChildren().add(nextQuestionLabelUI);
panelGrid.getChildren().add(nextQuestionDropDown) ;
RequestContext.getCurrentInstance().update("panel_grid");
}