1

Ok i have a problem here. I have a baseTemplate.xhtml:

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
  xmlns:ui="http://java.sun.com/jsf/facelets"
  xmlns:h="http://java.sun.com/jsf/html"
  xmlns:p="http://primefaces.org/ui"
  xmlns:f="http://java.sun.com/jsf/core">

<h:head>
    <!-- Incluir Scripts e Folhas de Estilo comuns a todas as páginas do sistema -->
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />        
    <h:outputStylesheet library="css" name="default.css"/>
    <h:outputStylesheet library="css" name="cssLayout.css"/>
    <h:outputStylesheet library="css" name="rodape.css"/>


    <title>SisEventos - Sistema de Gerenciamento de Eventos</title>
</h:head>
<h:body>
    <div class="estrutura">
        <div class="top">
        </div>

        <div class="menu">
            <!-- <ui:insert name="menu"> -->
            <h:form id="frmMenu"> 
                <p:menubar autoDisplay="true" >
                    <p:menuitem value="Home" icon="ui-icon-home" url="/paginas/home.xhtml" /> 

                    <p:submenu label="Manutenção" icon="ui-icon-person"> 
                        ...
                    </p:submenu> 

                    <p:submenu label="Atividades" > 
                        ...
                    </p:submenu> 

                    <p:submenu label="Relatórios" > 
                        ...
                    </p:submenu> 

                    <p:submenu label="Evento" > 
                        ...
                    </p:submenu> 

                    <p:menuitem value="Contato" /> 
                </p:menubar>
            </h:form>
        </div>

        <div class="left_content">
            <ui:insert name="content">
            </ui:insert>
        </div>

        <div class="bottom">
           ...
        </div>
    </div>  
</h:body>

And a client page like this:

<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns:ui="http://java.sun.com/jsf/facelets"
            xmlns:h="http://java.sun.com/jsf/html"
            xmlns:f="http://java.sun.com/jsf/core"
            xmlns:p="http://primefaces.org/ui"
            template="./../../resources/templates/baseTemplate.xhtml">

<ui:define name="content">
    <!-- Configuração do idioma de exibição do scheduler -->
    <h:outputScript library="scripts" name="primefaces-locale.js"/>
    <p:fieldset legend="Gerenciar eventos">

        <h:form id="frmEventos">
            <!-- Exibição de mensagens gerais -->
            <p:growl id="gMessages" sticky="false" globalOnly="true" />

            <p:schedule id="schedEventos" 
                        value="#{eventoBeanTeste.listaEventos}" 
                        widgetVar="schEventos" locale="pt">
                <p:ajax event="eventSelect" 
                        listener="#{eventoBeanTeste.onEventSelect}" 
                        update="frmEventos"
                        oncomplete="dlgNovo.show();"/>
                <p:ajax event="dateSelect" 
                        listener="#{eventoBeanTeste.onDateSelect}"
                        update="frmEventos"
                        oncomplete="dlgNovo.show();"/>
            </p:schedule>

            <p:dialog id="dlgNovoEvento" 
                      widgetVar="dlgNovo" 
                      modal="true" 
                      header="Novo evento"
                      resizable="false" 
                      draggable="true">
                <p:panelGrid id="pgNovoEvento" columns="1" styleClass="gridNoLine">
                    <p:row>
                        <p:messages id="mNovoMessages" redisplay="false"/>
                    </p:row>

                    ...

                    <p:row>
                        <p:commandButton value="Cancelar"
                                         immediate="true"
                                         onclick="dlgNovo.hide();"/>

                        <p:commandButton id="cbNovoSalvar" 
                                         value="Salvar" 
                                         actionListener="#{eventoBeanTeste.cadastrarEvento}"
                                         oncomplete="schEventos.update(); handleAction(xhr, status, args);" 
                                         update="@form frmEventos:gMessages"/>
                    </p:row>
                </p:panelGrid>
            </p:dialog>
        </h:form>

    </p:fieldset>

    <script type="text/javascript">
        function handleAction(xhr, status, args){
            if(args.close){
                dlgNovo.hide();
            }
        }
    </script>
</ui:define>

An action in the bean as follows:

@ManagedBean(name = "eventoBeanTeste")
@SessionScoped
public class EventoBeanTeste {

    ...

    // Listener de cadastro de evento
    public void cadastrarEvento(ActionEvent e) {
        MessageHelper.showGlobalMessage("Fired!", FacesMessage.SEVERITY_INFO);
    }
    ...
}

My problem is: the cadastrarEvento action listener doesn't get called! Seems that the commandButton is not working! What might be wrong?

mnatan.brito
  • 883
  • 5
  • 18
  • 32

2 Answers2

0

I've learned it is good practice to put a form in a dialog. If you do this you should be careful not to nest forms. So put it outside from your current form "frmEventos".

I guess the actionlistener will now be invoked.

And take a look at this thread: Primefaces Dialog

<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns:ui="http://java.sun.com/jsf/facelets"
        xmlns:h="http://java.sun.com/jsf/html"
        xmlns:f="http://java.sun.com/jsf/core"
        xmlns:p="http://primefaces.org/ui"
        template="./../../resources/templates/baseTemplate.xhtml">

<ui:define name="content">
    <!-- Configuração do idioma de exibição do scheduler -->
    <h:outputScript library="scripts" name="primefaces-locale.js"/>
    <p:fieldset legend="Gerenciar eventos">

            <p:dialog id="dlgNovoEvento" 
                  widgetVar="dlgNovo" 
                  modal="true" 
                  header="Novo evento"
                  resizable="false" 
                  draggable="true">
                <h:form>
                     <p:panelGrid id="pgNovoEvento" columns="1" styleClass="gridNoLine">
                         <p:row>
                             <p:messages id="mNovoMessages" redisplay="false"/>
                         </p:row>

                          ...

                         <p:row>
                             <p:commandButton value="Cancelar"
                                         immediate="true"
                                         onclick="dlgNovo.hide();"/>

                             <p:commandButton id="cbNovoSalvar" 
                                     value="Salvar" 
                                     actionListener="#{eventoBeanTeste.cadastrarEvento}"
                                     oncomplete="schEventos.update(); handleAction(xhr, status, args);" 
                                     update="@form frmEventos:gMessages"/>
                         </p:row>
                 </p:panelGrid>
            </h:form>
        </p:dialog>

        <h:form id="frmEventos">
            <!-- Exibição de mensagens gerais -->
            <p:growl id="gMessages" sticky="false" globalOnly="true" />

            <p:schedule id="schedEventos" 
                    value="#{eventoBeanTeste.listaEventos}" 
                    widgetVar="schEventos" locale="pt">
                <p:ajax event="eventSelect" 
                    listener="#{eventoBeanTeste.onEventSelect}" 
                    update="frmEventos"
                    oncomplete="dlgNovo.show();"/>
                <p:ajax event="dateSelect" 
                    listener="#{eventoBeanTeste.onDateSelect}"
                    update="frmEventos"
                    oncomplete="dlgNovo.show();"/>
            </p:schedule>


        </h:form>

    </p:fieldset>

    <script type="text/javascript">
        function handleAction(xhr, status, args){
            if(args.close){
                dlgNovo.hide();
            }
        }
    </script>
</ui:define>
Community
  • 1
  • 1
nik the lion
  • 458
  • 1
  • 9
  • 22
-1

Change your command button to <p:commandButton id="cbNovoSalvar" value="Salvar" action="#{eventoBeanTeste.cadastrarEvento}"
update="@form frmEventos:gMessages"/>
and remove the ActionEvent parameter from the function in the backing bean.

Ronald91
  • 1,736
  • 1
  • 15
  • 23
  • 1
    How exactly does this answer explain and solve OP's concrete problem? Or is this just a wild guess / stab-in-the-dark? – BalusC Sep 25 '12 at 20:10
  • @Ronald91 I've done as you said but it didn't work! At least for me, seems to be a conflict with the two form components, one in the baseTemplate.xhtml and the other in the gerenciarEventoTeste.xhtml – mnatan.brito Sep 25 '12 at 21:03