I'm trying to call a method in my ManagedBean, but the form is not submitted. Detail. I have a dialog that inside it I have some includes of other xhtml files, it follows like this until the moment
This is my 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>
<ui:include src="bancoPerguntasQuestaoQuiz.xhtml" />
</p:outputPanel>
<p:outputPanel
rendered="#{bancoPerguntasMBean.mecanicaSelecionada == '2'}">
<ui:include src="bancoPerguntasQuestaoVerdadeiroFalso.xhtml" />
</p:outputPanel>
<p:outputPanel
rendered="#{bancoPerguntasMBean.mecanicaSelecionada == '3'}">
<ui:include src="bancoPerguntasQuestaoDescritiva.xhtml" />
</p:outputPanel>
<p:outputPanel
rendered="#{bancoPerguntasMBean.mecanicaSelecionada == '4'}">
<ui:include src="bancoPerguntasQuestaoAssociacao.xhtml" />
</p:outputPanel>
<p:outputPanel
rendered="#{bancoPerguntasMBean.mecanicaSelecionada == '5'}">
<ui:include src="bancoPerguntasQuestaoArrastaSolta.xhtml" />
</p:outputPanel>
</p:dialog>
</h:form>
And this is my file that I'm trying to call the unsuccessful method in MB
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
Create Alternative
<p:selectBooleanCheckbox
value="#{bancoPerguntasMBean.novaAlternativaCorretaQuiz}"
itemLabel="Verdadeira" />
<br />
<p:inputTextarea rows="3" cols="100" maxlength="1000"
value="#{bancoPerguntasMBean.novaAlternativaQuiz}"
placeholder="Digite uma alternativa"
counter="contadorCaracteresAlt"
counterTemplate="{0} caracteres restantes."
styleClass="inputAlternativaQuiz input-padrao">
<p:ajax event="keypress"
oncomplete="keyPressInputObrigatorio('inputAlternativaQuiz');" />
</p:inputTextarea>
<p:spacer width="20px" />
<br />
<h:outputText id="contadorCaracteresAlt" />
<br />
<p:commandButton value="Criar Alternativa"
action="#{bancoPerguntasMBean.criarNovaAlternativaQuiz}">
<f:ajax render="quizAlternativasPanel" execute="@this"
resetValues="true" />
</p:commandButton>
</p:panel></td>
</tr>
<tr>
<th>Alternativas Criadas</th>
</tr>
<tr>
<td><p:panel id="quizAlternativasListPanel"
styleClass="painelLimpo">
<p:dataTable var="alternativa" id="alternativasTable"
value="#{bancoPerguntasMBean.listaQuizAlternativas}"
emptyMessage="Nenhuma alternativa foi criada ainda."
tableStyleClass="table-list-contents">
<p:column style="background-color:#fff;">
<p:commandButton
value="(x) #{alternativa.alternativa} #{alternativa.correta == 1 ? ' - Correta' : ' - Errada'}"
style="background-color:#FF4500;"
action="#{bancoPerguntasMBean.removeAlternativaQuiz(alternativa)}">
<f:ajax render="quizAlternativasListPanel" execute="@this"
resetValues="true" />
<p:confirm header="Confirmação"
message="Deseja realmente apagar essa alternativa?"
icon="ui-icon-alert" />
</p:commandButton>
</p:column>
</p:dataTable>
</p:panel></td>
</tr>
<tr>
<td><p:panel id="quizBotaoCriarPanel" styleClass="painelLimpo">
<p:commandButton id="btnCriarQuiz" value="Criar Questão Quiz"
styleClass="btnCriarQuestao"
actionListener="#{bancoPerguntasMBean.criarNovaQuestaoQuiz}"
onclick="return validaInputObrigatorio('inputEnunciadoQuiz');"
resetValues="true" update="modalMecanica">
<f:ajax render="quizAlternativasListPanel" execute="@this"
resetValues="true" />
<p:confirm header="Confirmação"
message="Deseja realmente adicionar essa questão de Quiz na avaliação?"
icon="ui-icon-alert" />
</p:commandButton>
</p:panel></td>
</tr>
</table>
</h:form>
<p:confirmDialog global="true" responsive="true" width="500"
styleClass="painelConfirmacao">
<p:commandLink styleClass='bt bt-p bt-action ui-confirmdialog-yes'
value="Sim" />
<p:commandLink styleClass='bt bt-p bt-del ui-confirmdialog-no'
value="Não" />
</p:confirmDialog>
On the button, it has no action on MB
<p:commandButton value="Criar Alternativa"
action="#{bancoPerguntasMBean.criarNovaAlternativaQuiz}">
<f:ajax render="quizAlternativasPanel" execute="@this"
resetValues="true" />
</p:commandButton>
Is this because it is already inside a form, the one in the dialog?
This is my MB method that should be called when clicking the commandButton
public void criarNovaAlternativaQuiz() {
BancoPerguntasMecanicaQuiz objMecanicaQuiz = new BancoPerguntasMecanicaQuiz();
try {
if (StringUtils.isNullOrEmpty(this.novaAlternativaQuiz)) {
return;
}
for (BancoPerguntasMecanicaQuiz alternativa : this.listaMecanicaQuiz) {
if (alternativa.getAlternativa().equals(this.novaAlternativaQuiz)) {
String erro = "Essa alternativa já foi incluída";
RequestContext.getCurrentInstance().execute("exibeErroNovaAvaliacao('" + erro + "');");
return;
}
}
objMecanicaQuiz.setAlternativa(this.novaAlternativaQuiz);
objMecanicaQuiz.setCorreta(this.novaAlternativaCorretaQuiz ? 1 : 0);
this.listaMecanicaQuiz.add(objMecanicaQuiz);
this.novaAlternativaQuiz = null;
this.novaAlternativaCorretaQuiz = false;
} catch (Exception e) {
String erro = ExceptionUtil.trataErrosCriacaoQuestaoQuiz(e);
RequestContext.getCurrentInstance().execute("exibeErroNovaAvaliacao('" + erro + "');");
}
}