2016-12-28 74 views
0

我需要幫助。我有一個'form',它通過p:commandButton調用p:dialog。該p:對話框包含其他p:commandButton,但第二個按鈕不會採取任何操作,這對我來說很奇怪,因爲第一個按鈕可以正常工作。primefaces命令按鈕不採取行動

代碼:

<ui:define name="body">    
     <br/> 
     <br/> 
     <br/> 
     <p:ajaxStatus onstart="PF('statusDialog').show()" onsuccess="PF('statusDialog').hide()" /> 
     <p:dialog widgetVar="statusDialog" modal="true" draggable="false" closable="false" resizable="false" showHeader="false"> 
      <p:graphicImage value="/resources/Images/ajax-loader.gif" alt="Por favor espere..." /> 
     </p:dialog> 

     <h:form id="BuscarEmpresaForm"> 
      <h:panelGroup id="display"> 
       <h:panelGrid columns="2" style="margin-left: 10px;"> 
        <p:outputLabel value="#{bundle.BuscarEmpresaBuscarLabel}" /> 
        <h:outputLabel/> 
        <h:selectOneRadio id="idBusquedaRadio" value="#{cupoController.radioButtonBusqueda}"> 
         <f:selectItem itemLabel="#{bundle.BuscarEmpresaCodigoLabel}" itemValue="Codigo" /> 
         <f:selectItem itemLabel="#{bundle.BuscarEmpresaNombreLabel}" itemValue="Nombre" /> 
        </h:selectOneRadio> 
        <h:outputLabel/> 
        <p:inputText id="empresa" value="#{cupoController.empresaTextoBusqueda}" required="true" requiredMessage="El campo es requerido"/> 

        <!--THIS BUTTON WORKS--> 

        <p:commandButton value="Buscar" actionListener="#{cupoController.prepareCreateEmpresa()}" action="#{cupoController.searchEmpresa()}" oncomplete="PF('dlg1').show();" update=":confirmDialogEmpresa">        
        </p:commandButton> 
        <p:message for="empresa"/> 

       </h:panelGrid> 
      </h:panelGroup> 
     </h:form> 
     <p:dialog id="dialog1" header="Mensaje" widgetVar="dlg1" minHeight="40" modal="true" appendTo="@(body)"> 
      <h:form id="confirmDialogEmpresa"> 
       <h:panelGroup id="display"> 
        <h:panelGrid columns="2" rendered="#{cupoController.selectedEmpresa.codcor != null}"> 
         <p:outputLabel value="Empresa encontrada, Continuar?"/> 
         <h:outputLabel/>        
         <p:outputLabel value="Nombre: #{cupoController.selectedEmpresa.razonsocial}"/> 
         <h:outputLabel/> 
         <p:outputLabel value="RUC: #{cupoController.selectedEmpresa.ruc}"/> 
         <h:outputLabel/> 

         <!--THIS BUTTON DOES NOT WORK--> 

         <p:commandButton value="Si" action="#{cupoController.buscarCupo}" icon="ui-icon-check"/> 
         <p:commandButton value="No" onclick="dlg1.hide();" icon="ui-icon-close" update="@none"/> 
        </h:panelGrid> 
        <h:panelGrid columns="2" rendered="#{cupoController.selectedEmpresa.codcor == null}" > 
         <p:outputLabel value="Empresa no encontrada"/> 
         <h:outputLabel/> 
         <p:messages /> 
         <h:outputLabel/> 
         <p:commandButton value="Aceptar" onclick="dlg1.hide();" icon="ui-icon-close" update="@none"/> 
        </h:panelGrid> 
       </h:panelGroup> 
      </h:form> 
     </p:dialog> 

    </ui:define> 

我已經做了一些嘗試更換號碼:對的commandButton H:的commandButton,但有相同的結果。

An image showing what code outs

在此先感謝。

+0

我認爲你試圖在點擊按鈕後確認一個動作。爲此,您應該使用primefaces提供的[ConfirmDialog](http://www.primefaces.org/showcase/ui/overlay/confirmDialog.xhtml)組件。 – cdaiga

+0

是的,你說得對。但我需要做自定義操作。這就是爲什麼我選擇這種方式。 THKS –

回答

0

我發現了這個問題,並且相關的話題:Backing beans (@ManagedBean) or CDI Beans (@Named)?

在我來說,我很困惑。我將CDI註釋與託管bean中的JSF註釋混合在一起,產生了一種奇怪的行爲。最後,我修復了讓JSF註釋。

核心:JSF 2.0,PrimeFaces 5.0,GlassFish 4.1