1

好的,我这里有问题。我有一个 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>

和这样的客户页面:

<?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>

bean中的一个动作如下:

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

    ...

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

我的问题是:没有调用 cadastrarEvento 动作监听器!似乎命令按钮不起作用!可能有什么问题?

4

2 回答 2

0

我了解到将表单放入对话框中是一种很好的做法。如果你这样做,你应该小心不要嵌套表格。所以把它放在你当前的表单“frmEventos”之外。

我猜现在将调用 actionlistener。

看看这个线程: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>
于 2014-06-29T19:50:56.657 回答
-1

将命令按钮更改为 并从支持 bean 的函数中删除 ActionEvent 参数。<p:commandButton id="cbNovoSalvar" value="Salvar" action="#{eventoBeanTeste.cadastrarEvento}"
update="@form frmEventos:gMessages"/>

于 2012-09-25T18:42:43.767 回答