0
Hello, I’m trying to open a dialog with a selectonemenu, depending on what the user selects. My Selectonemenu looks like this
<p:column headerText="Mecânica">
<h:commandButton>
<h:selectOneMenu value="#{bancoPerguntasMBean.mecanica}"
id="mecanica" onchange="PF('cadastraMecanica').show();"
rendered="#{document.type == 'Pergunta'}">
<f:selectItem itemLabel="Selecione a mecânica"
noSelectionOption="true" />
<f:selectItems value="#{bancoPerguntasMBean.mecanicas}" />
</h:selectOneMenu>
</h:commandButton>
</p:column>
And My dialog is like this
<h:form id="cadastraMecanica">
<p:dialog style="text-align: center" header="Cadastrar Mecânica"
widgetVar="cadastraMecanica" resizable="false" modal="true"
width="1050" height="630">
<p:outputPanel rendered="#{bancoPerguntasMBean.mecanica == 'QUIZ'}">
<ui:include src="bancoPerguntasQuestaoQuiz.xhtml" />
</p:outputPanel>
<p:outputPanel
rendered="#{bancoPerguntasMBean.mecanica == 'VERDADEIROFALSO'}">
<ui:include src="bancoPerguntasQuestaoVerdadeiroFalso.xhtml" />
</p:outputPanel>
<p:outputPanel
rendered="#{bancoPerguntasMBean.mecanica == 'DESCRITIVA'}">
<ui:include src="bancoPerguntasQuestaoDescritiva.xhtml" />
</p:outputPanel>
<p:outputPanel
rendered="#{bancoPerguntasMBean.mecanica == 'ASSOCIACAO'}">
<ui:include src="bancoPerguntasQuestaoAssociacao.xhtml" />
</p:outputPanel>
<p:outputPanel
rendered="#{bancoPerguntasMBean.mecanica == 'ARRASTASOLTA'}">
<ui:include src="bancoPerguntasQuestaoArrastaSolta.xhtml" />
</p:outputPanel>
</p:dialog>
</h:form>
My question is on how to properly open the dialog, with the correct file include. Note that depending on what is selected it does a different include, however I am not able to redeem the value selected by the user to validate in the dialog. Someone to help out?
Updating
I refactored the code to try to open the correct include, but without success, it follows refactoring
<p:column headerText="Mecânica" style="text-align: center">
<p:selectOneMenu id="mecanicas"
value="#{bancoPerguntasMBean.mecanicaSelecionada}"
required="true" widgetVar="sel"
onchange="PF('modalMecanica').show(); getMecanicaSelecionada()"
rendered="#{document.type == 'Pergunta'}">
<f:selectItem itemLabel="Selecione a mecânica" itemValue=""
noSelectionOption="true" />
<f:selectItems value="#{bancoPerguntasMBean.mecanicas}"
var="mecanica" id="mecanica" itemValue="#{mecanica.nome}"
rendered="#{mecanica.nome != 'IMAGEM RESPOSTA'}"
itemLabel="#{mecanica.nome}" />
</p:selectOneMenu>
</p:column>
Here the dialog
<h:form id="modalMecanica">
<p:dialog style="text-align: center" header="Cadastrar Mecânica"
widgetVar="modalMecanica" resizable="false" modal="true"
width="1050" height="630">
<p:outputPanel
rendered="#{bancoPerguntasMBean.mecanicaSelecionada == 'QUIZ'}">
<ui:include src="bancoPerguntasQuestaoQuiz.xhtml" />
</p:outputPanel>
<p:outputPanel
rendered="#{bancoPerguntasMBean.mecanicaSelecionada == 'VERDADEIRO FALSO'}">
<ui:include src="bancoPerguntasQuestaoVerdadeiroFalso.xhtml" />
</p:outputPanel>
<p:outputPanel
rendered="#{bancoPerguntasMBean.mecanicaSelecionada == 'DESCRITIVA'}">
<ui:include src="bancoPerguntasQuestaoDescritiva.xhtml" />
</p:outputPanel>
<p:outputPanel
rendered="#{bancoPerguntasMBean.mecanicaSelecionada == 'ASSOCIACAO'}">
<ui:include src="bancoPerguntasQuestaoAssociacao.xhtml" />
</p:outputPanel>
<p:outputPanel
rendered="#{bancoPerguntasMBean.mecanicaSelecionada == 'ARRASTA SOLTA'}">
<ui:include src="bancoPerguntasQuestaoArrastaSolta.xhtml" />
</p:outputPanel>
</p:dialog>
</h:form>
The dialog opens correctly, however empty, is not performing any include. In the bean I created an attribute that receives the selected guy
private String mecanicaSelecionada;
Have you solved it? The dialog is not opening...?
– Marlysson
Hello Marlysson, I edited the publication with a new refactoring, however I could not do include. The dialog opens normally, but empty. Can fill up where I might be missing?
– Michael Soares
First: Are your pages in the same directory as the dialog? Second: your included pages should contain the <ui:Composition> tag without the html headers.. only with the content..
– Marlysson
The pages are in the same directory, and also with the <ui:Composition> tag. I did testo by just doing include without the rendered, normally opens the sliders. It is getting lost when selecting the selectonemenu. I believe the bean is not redeeming the selected value correctly
– Michael Soares
Try placing a <f:ajax process="@this" /> inside the selectOneMenu.
– Marlysson