5
I’m calling a Dialog via a JSF button with Primefaces 5.1
enabling the Dialog through the onstart="PF('iconeDeProcessamento').show()" button.
Can anyone tell if it is possible to pass a parameter to the dialog ?
What I really intend to do:
The dialogue iconeDeProcessamento is standard for three buttons that call processamentod different.
In the dialogue I have the parameter header="#{TA_MB.tituloProcessamento}" with the EL in question.
I’d like to change the value of EL TA_MB.tituloProcessamento to be presented in the dialogue.
Ex:
Button 1 calls the dialog and shows as title "Wait... Searching Data"
Button 2 calls the dialog and shows as title "Wait... Calculating"
Button 3 calls the dialog and shows as title "Wait... Recording"
Button Code that calls 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>
Add-on. Attempt using ajax - Also not working. 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());
}
How are you importing the facelets from this dialog? It’s set in your template? My suggestion is to create one
ui:insertwith the value to be set on each screen and use aui:defineto define this value, having a default in case there is no definition.– Wakim
It would be nice to include the code snippet where you declare your
dialogon the page. Just to have a view of where the dialog is and the button.– Wakim
I’m using facelets only on the main page. for p:dialog I don’t use facelets. I can try with facelets as suggested, but how will I make the event call
onstartbutton?– Marcelo
Marcelo, how are you calling the
dialogright on the client, without making a request to the server/Bean, my suggestion is to change the title by Javascript, taking theh:outputTextby id and changing its value. Not the best solution. The most correct would be to invoke thedialogwithout Javascript, only withactionbutton, but it is a waste of resources.– Wakim
I used very little Java not to say anything. You have some example?
– Marcelo
Puts in your
onstart:onstart="PF('iconeDeProcessamento').show(); document.getElementById('dialogHeader').innerHTML = 'TITULO_HEADER';"oronstart="PF('iconeDeProcessamento').show(); document.querySelector('#dialogHeader').innerHTML = 'TITULO_HEADER';"– Wakim
It didn’t work either. From what I noticed the second command of the line ( after ; ) is not executed or the direct js command does not work.
– Marcelo
You could, for each button set a title in the Managed Bean attribute, and on each button update (using the attribute
update) dialog (by ajax). Then just display the window at the end of the execution (using the attributeoncomplete).– Cold
See if I did what Oce suggested (add-on) ? .
– Marcelo