How to pass parameter to a dialog with PrimeFaces?

5

I'm calling a Dialog through a button in JSF with PrimeFaces 5.1 enabling Dialog through onstart="PF('iconeDeProcessamento').show()" of the button.

Does anyone know if it is possible to pass a parameter to the dialog?

What I really want to do: The iconeDeProcessamento dialog defaults to three buttons that call processamentod different. In the dialog I have the parameter header="#{TA_MB.tituloProcessamento}" with the EL in question. I would like to change the EL TA_MB.tituloProcessamento value to be displayed in the dialog.

Ex:

Button 1 calls the dialog and shows the title "Please Wait ... Searching Data"
Button 2 calls the dialog and shows the title "Wait ... Calculating"
Button 3 calls the dialog and shows the title "Wait ... Recording"

Button code calling the dialog

<p:commandButton id="consulta" disabled="#{TA_MB.ctrlEntrada}" 
   value="Busca    movimento" 
   actionListener="#{TA_MB.buscarLinhas}" icon="ui-icon-bookmark"
   styleClass="botao-parametro" 
   update="anoMes consulta novarequisicao linhasTA calculoTA gravaTA"
   onstart="PF('iconeDeProcessamento').show()"
   onsuccess="PF('iconeDeProcessamento').hide()" >
</p:commandButton>

Dialogue

<p:dialog widgetVar="iconeDeProcessamento" modal="true" draggable="false"
 closable="false" resizable="false" showHeader="true" appendTo="@(body)"
 header="#{TA_MB.tituloProcessamento}" style="width:20%;height:20%" >

  <p:graphicImage id="progressoGif" value="../resources/img/loader_blue.gif"
  style="width:40%;height:40%; display: block; margin-left: auto; margin-right: auto"/>
</p:dialog>

xHtml with the tags in question

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:p="http://primefaces.org/ui" > 

     <h:outputStylesheet name="/resources/css/estilo.css" library="css" />              

      <ui:composition template="/WEB-INF/templates/t_estrutural.xhtml">

            <ui:param name="render_east" value="true" />        
            <ui:param name="render_west" value="false" />
            <ui:param name="headerTitulo" value="Parametros" />

            <ui:define name="titulo">Calcula TA</ui:define>

            <ui:define name="mensagem">

                    <h:panelGrid columns="1">
                        <p:button id="btHome" outcome="principal" value="Home" icon="ui-icon-home" styleClass="botao-parametro" />

                            <h:outputLabel value="Ano/Mes:" for="anoMes"/>
                            <p:inputMask disabled="#{TA_MB.ctrlEntrada}" id="anoMes" value="#{TA_MB.anoMes}" validatorMessage="Periodo invalido" mask="9999/99" >
                                <f:validateRegex pattern="20[0-9]{2}/[0-9]{2}" />
                            </p:inputMask>

                            <p:commandButton id="consulta" disabled="#{TA_MB.ctrlEntrada}" value="Busca movimento" 
                                     actionListener="#{TA_MB.buscarLinhas}" icon="ui-icon-bookmark"
                                     styleClass="botao-parametro" 
                                     update="anoMes consulta novarequisicao linhasTA calculoTA gravaTA iconeDeProcessamento"
                                     onstart="PF('iconeDeProcessamento').show()"
                                     onsuccess="PF('iconeDeProcessamento').hide()" >
                                     <f:setPropertyActionListener target="#{TA_MB.tituloProcessamento}" value="Aguarde... Buscando dados"/>     
                            </p:commandButton>

                            <p:commandButton id="calculoTA" disabled="#{TA_MB.ctrlProcessamento}" value="Calcular TA" 
                                     actionListener="#{TA_MB.calcularTA}" icon="ui-icon-bookmark"
                                     styleClass="botao-parametro" 
                                     update="linhasTA"
                                     onstart="PF('iconeDeProcessamento').show()"
                                     onsuccess="PF('iconeDeProcessamento').hide()" >
                                     <f:setPropertyActionListener target="#{TA_MB.tituloProcessamento}" value="Aguarde... Calculando"/>     
                            </p:commandButton>

                            <p:commandButton id="gravaTA" disabled="#{TA_MB.ctrlProcessamento}" value="Grava TA" 
                                     actionListener="#{TA_MB.gravarTA}" icon="ui-icon-disk"
                                     styleClass="botao-parametro" 
                                     update="linhasTA"
                                     onstart="PF('iconeDeProcessamento').show()"
                                     onsuccess="PF('iconeDeProcessamento').hide()">
                                     <f:setPropertyActionListener target="#{TA_MB.tituloProcessamento}" value="Aguarde... Gravando"/>   
                                     <p:confirm header="Confirma ?" message="Confirma gravação dos Dados?" icon="ui-icon-alert" />
                            </p:commandButton>                                           

                            <p:button id="novarequisicao" disabled="#{TA_MB.ctrlProcessamento}" value="Nova Consulta" styleClass="botao-parametro" icon="ui-icon-refresh" outcome="taCalculo"/>                                                                                         

                    </h:panelGrid>

            </ui:define>

            <ui:define name="corpo">
                    <p:growl id="messages" showDetail="true" showSummary="false" autoUpdate="true" closable="true" />
                    <!--  ***********************************  Dialogo do progresso   ************************************************* -->
                    <p:dialog id='iconeDeProcessamento' widgetVar="iconeDeProcessamento" modal="true" draggable="false" closable="false" resizable="false" showHeader="true" appendTo="@(form)"
                            style="width:20%;height:20%" >
                            <f:facet name="header">
                <h:outputText id="dialogHeader" value="#{TA_MB.tituloProcessamento}" />                            
                        </f:facet>
                        <p:graphicImage id="progressoGif"  value="../resources/img/loader_blue.gif" style="width:40%;height:40%; display: block; margin-left: auto; margin-right: auto"/>
                    </p:dialog>
            </ui:define>
      </ui:composition> 

</html>

Complement. Attempt using ajax - Also did not work. xHTML

<p:commandButton id="consulta" disabled="#{TA_MB.ctrlEntrada}" value="Busca movimento" 
         actionListener="#{TA_MB.buscarLinhas()}" icon="ui-icon-bookmark"
         styleClass="botao-parametro" 
         update="anoMes consulta novarequisicao linhasTA calculoTA gravaTA iconeDeProcessamento"
         onsuccess="PF('iconeDeProcessamento').hide()" >
         <p:ajax update="iconeDeProcessamento" onstart="#{TA_MB.mudaTitulo()}" oncomplete="PF('iconeDeProcessamento').show()">
            <f:param name="titulo" value="Aguarde... Buscando Dados"/>
         </p:ajax>
</p:commandButton>

Managed Bean

public void mudaTitulo(){
    Map<String,String> params = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap();
    String titulo = params.get("titulo");
    this.setTituloProcessamento(titulo);
    System.out.printf("------ verifica mudaTitulo() [ %s ] ",getTituloProcessamento());
}
    
asked by anonymous 06.01.2015 / 17:44

1 answer

1

When the button fires you can change the value of the #{TA_MB.tituloProcessamento} using <f:setPropertyActionListener /> and update a component that contains the dialog title as follows:

<p:commandButton actionListener="#{TA_MB.buscarLinhas}"
   <!-- atualiza componente do título -->
   update="dialogHeader" 
   onstart="PF('iconeDeProcessamento').show()"
   onsuccess="PF('iconeDeProcessamento').hide()" >

    <!-- altera propriedade do título -->
    <f:setPropertyActionListener target="#{TA_MB.tituloProcessamento}" value="seuTitulo" />   

</p:commandButton>

Dialog with updateable title

<p:dialog widgetVar="iconeDeProcessamento" >
    <f:facet name="header">
        <!-- componente que será atualizado -->
        <h:outputText id="dialogHeader" value="#{TA_MB.tituloProcessamento}" />                           
    </f:facet>
</p:dialog>

Note: attribute header of <p:dialog> will be overwritten with this <f:facet name="header>

    
06.01.2015 / 20:32