How to put a passing parameter into <p:confirm message="">? - jsf

This is what I've got:
<p:growl id="message" showDetail="true" />
<p:commandButton value="delete user" actionListener="#{bean.deleteUser(user)}" update="#form">
<p:confirm header="Confirm" message="Are you sure to delete #{user.username}?" icon="ui-icon-alert" />
</p:commandButton>
<p:confirmDialog global="true" showEffect="fade" hideEffect="fade">
<p:commandButton value="yes" type="button" styleClass="ui-confirmdialog-yes" icon="ui-icon-check" />
<p:commandButton value="No" type="button" styleClass="ui-confirmdialog-no" icon="ui-icon-close" />
</p:confirmDialog>
The variable #{user.username} won't be shown at all.
what am I doing wrong?

Related

p:selectManyMenu deselect confirmation

I try to get a confirmation dialog when i deselect an item from a mutli-select p:selectManyMenu.
<p:outputLabel for="ccs" value="CS" styleClass="toplabel"/>
<p:selectManyMenu id="ccs" value="#{ccView.selectedCSs}"
var="cs" filter="true" filterMatchMode="contains" showCheckbox="true">
<p:ajax event="change" listener="#{ccView.onCSChanged}" />
<f:selectItems value="#{ccView.CSs}" var="source" itemLabel="#{source.name}" itemValue="#{source}" />
<p:column>
<h:outputText value="#{cs.name}" />
</p:column>
</p:selectManyMenu>
now, if an item is deselected (checkbox change to unchecked) i want to show a confirmation dialog.
<p:confirmDialog global="true" showEffect="fade" hideEffect="fade">
<p:commandButton value="Yes" type="button" styleClass="ui-confirmdialog-yes" icon="ui-icon-check" />
<p:commandButton value="No" type="button" styleClass="ui-confirmdialog-no" icon="ui-icon-close" />
</p:confirmDialog>
I tried it with ajax events like "unselect", "deselect", "rowUnselect"..
any idea?

Primefaces confirmDialog with EL variables and in modal Window

I have a strange problem with Primefaces' confirm Dialog.
What I need is a confirmation dialog that displays some variables im my Bean, working in a modal dialog window and firing a Bean method. But it seems I can't get the 3... :-(
Here is what I've been trying:
<p:confirmDialog header="Aviso de Confirmação"
closable="false"
appendToBody="true"
global="false"
showEffect="fade"
hideEffect="fade"
widgetVar="confirmDlg">
<h:form>
<f:facet name="message">
<h:outputText value="Confirma o registro de desistência do candidato(a) #{registrosCandidatoBean.candidatoInclusaoDesistencia.inscricao} - #{registrosCandidatoBean.candidatoInclusaoDesistencia.papelPessoa.pessoaFisica.nomeCompleto}?" />
</f:facet>
<p:commandButton value="Sim"
styleClass="ui-confirmdialog-yes"
icon="ui-icon-check"
action="#{registrosCandidatoBean.gravarDesistencia()}"
update=":formDesistencia :formMensagem:mensagemFixa"
ajax="false"
immediate="true" />
<p:commandButton value="Não"
styleClass="ui-confirmdialog-no"
icon="ui-icon-close"
onclick="confirmDlg.hide();" />
</h:form>
</p:confirmDialog>
*** This one displays the message and calls the method. But the "message" in f:facet is not displayed. Id I use the normal "message" attribute, It doesn't use the variables in my bean.
<p:confirmDialog header="Aviso de Confirmação"
closable="false"
appendToBody="true"
global="false"
showEffect="fade"
hideEffect="fade"
widgetVar="confirmDlg">
<f:facet name="message">
<h:outputText value="Confirma o registro de desistência do candidato(a) #{registrosCandidatoBean.candidatoInclusaoDesistencia.inscricao} - #{registrosCandidatoBean.candidatoInclusaoDesistencia.papelPessoa.pessoaFisica.nomeCompleto}?" />
</f:facet>
<p:commandButton value="Sim"
styleClass="ui-confirmdialog-yes"
icon="ui-icon-check"
action="#{registrosCandidatoBean.gravarDesistencia()}"
update=":formDesistencia :formMensagem:mensagemFixa"
ajax="false"
immediate="true" />
<p:commandButton value="Não"
styleClass="ui-confirmdialog-no"
icon="ui-icon-close"
onclick="confirmDlg.hide();" />
</p:confirmDialog>
*** This one displays the message and "message" in f:facet. But any Bean methods aren't called.
<p:confirmDialog header="Aviso de Confirmação"
closable="false"
global="false"
showEffect="fade"
hideEffect="fade"
widgetVar="confirmDlg">
<f:facet name="message">
<h:outputText value="Confirma o registro de desistência do candidato(a) #{registrosCandidatoBean.candidatoInclusaoDesistencia.inscricao} - #{registrosCandidatoBean.candidatoInclusaoDesistencia.papelPessoa.pessoaFisica.nomeCompleto}?" />
</f:facet>
<p:commandButton value="Sim"
styleClass="ui-confirmdialog-yes"
icon="ui-icon-check"
action="#{registrosCandidatoBean.gravarDesistencia()}"
update=":formDesistencia :formMensagem:mensagemFixa"
ajax="false"
immediate="true" />
<p:commandButton value="Não"
styleClass="ui-confirmdialog-no"
icon="ui-icon-close"
onclick="confirmDlg.hide();" />
</p:confirmDialog>
*** This one displays the message and "message" in f:facet. Apparently it calls the Bean methods, but I can't test it since the dialog is greyed and I can't click the buttons.
Can it work the way I need?
Primefaces 4.0
Thanks! :)
for the third scenario, try adding;
appendTo="#(body)"

Validation password doesn't work in p:dialog

I'm using PrimeFaces 4.0 and I'm trying to use a dialog to change password.
I used password component to do this job It does n't work in a dialog but It works fine when I'm not using Dialog.
Here is my code
<h:form>
<p:dialog widgetVar="changePw" resizable="true" appendTo="#(body)"
modal="true" closable="false" id="changePw">
<p:panel header="change password">
<p:messages id="messages" showDetail="true" showSummary="false"
autoUpdate="true" />
<h:panelGrid columns="2" id="matchGrid">
<h:outputLabel for="pwdNew" value="New: *" />
<p:password id="pwdNew" value="#{passwordBean.newPw}" feedback="true"
match="pwdConf" required="true"
validatorMessage="Pw does n't matches"
requiredMessage="Value required">
</p:password>
<p:messages showDetail="true" showSummary="false" autoUpdate="true"
for="pwdNew" />
<h:outputLabel for="pwdConf" value="Confirm Password: *" />
<p:password id="pwdConf" value="#{passwordBean.newPwConfirmation}"
feedback="true" required="true"
validatorMessage="invalid password"
requiredMessage="Value required">
<f:validateRegex pattern="[A-Za-z0-9]{8,60}" />
</p:password>
</h:panelGrid>
</p:panel>
<p:separator></p:separator>
<p:commandButton value="Save" update="matchGrid"
process="#this" ajax="true"
actionListener="#{passwordBean.changePw}"
styleClass="ui-confirmdialog-yes"
oncomplete="changePw.hide();"
icon="ui-icon-check" />
<p:commandButton value="Cancel" process="#this"
onclick="changePw.hide();" styleClass="ui-confirmdialog-no"
icon="ui-icon-close" />
</p:dialog>
...
Thank for any suggestion !
If you use a 'appendTo="#(body)"', you need a form IN the dialog as can be read in the PrimeFaces documentation. But make sure that it is in the original xhtml NOT nested!
In addition, the process="#this" on the buttons prevent the other inputs to be submitted (this also won't work outside the dialog, so you most likely did not have that there). So remove that as well

p:contextMenu within p:dataTable in PrimeFaces

I have a problem related to a <p:contextMenu> within a <p:dataTable> of PrimeFaces. There is a <p:commandLink> and also some command buttons within columns in this table, when I open the context menu automatically inserted is the value of that column my variable, but the problem is this when I open this <p:contexMenu> menu by clicking the right button on top of one of these link command or command button the value of this column is not passed to variable.
This is my code.
<h:form id="form-arquivo-listar">
<p:contextMenu id="menuArquivos" for="dataArquivos">
<p:menuitem value="Baixar" icon="ui-icon-disk" url="../../arquivos/#{arquivoBean.arquivoSelecionado.nome}" target="arquivo"/>
<p:menuitem value="Excluir" icon="ui-icon-close" actionListener="#{arquivoBean.excluir()}" update="form-arquivo-listar"/>
<p:menuitem value="Transferir" icon="ui-icon-extlink" actionListener="#{arquivoBean.getPastas()}" update=":formArquivoTransferir:treeArquivos" oncomplete="PF('arquivoTransferirDialog').show()"/>
</p:contextMenu>
<p:menubar model="#{arquivoBean.menu}"/>
<p:dataTable id="dataArquivos" value="#{arquivoBean.objetos}" var="o" rowKey="#{o.id}" selection="#{arquivoBean.arquivoSelecionado}" selectionMode="single" styleClass="ui-datatable-no-border">
<f:facet name="header">#{text['arquivo.pagina.listar.titulo']}</f:facet>
<p:column style="width: 20px">
<i class="#{o.tipo.icone}"></i>
</p:column>
<p:column headerText="#{text['arquivo.pagina.form.nome']}" rendered="#{o.tipo.id != 5}">
<p:link value="#{o.nomeOriginal}" href="../../arquivos/#{o.nome}" target="arquivo">
</p:link>
</p:column>
<p:column headerText="#{text['arquivo.pagina.form.nome']}" rendered="#{o.tipo.id == 5}">
<p:commandLink styleClass="link" id="link" value="#{o.nomeOriginal}" actionListener="#{arquivoBean.alterarPasta(o.id)}" update=":form-arquivo-listar" >
</p:commandLink>
</p:column>
<p:column headerText="#{text['arquivo.pagina.form.publico']}" style="width: 50px">
<h:outputText value="#{o.publico ? 'Sim' : 'Não'}" rendered="#{o.tipo.id != 5}"/>
</p:column>
<p:column style="width: 26px">
<p:commandButton id="editarButton" title="Exibir" icon="ui-icon-search" update=":form-arquivo-listar:arquivo-detalhes" oncomplete="PF('arquivoDialog').show()" rendered="#{o.tipo.id != 5}">
<f:setPropertyActionListener value="#{o}" target="#{arquivoBean.objeto}" />
</p:commandButton>
</p:column>
<p:column style="width: 26px">
<p:commandButton icon="ui-icon-pencil" oncomplete="PF('cadastroArquivo').show()">
<f:setPropertyActionListener value="#{o}" target="#{arquivoBean.objeto}" />
</p:commandButton>
</p:column>
<p:column style="width: 26px">
<p:commandButton id="excluirButton" title="#{text['arquivo.pagina.form.confirmacao.botao.titulo']}" icon="ui-icon-close" update=":form-arquivo-listar" actionListener="#{arquivoBean.excluir(o.id)}">
<p:confirm header="#{text['arquivo.pagina.form.confirmacao.titulo']}" icon="ui-icon-alert" message="#{text['arquivo.pagina.form.confirmacao.mensagem']}" />
</p:commandButton>
<p:confirmDialog global="true" showEffect="fade" hideEffect="fade">
<p:commandButton icon="ui-icon-check" value="#{text['arquivo.pagina.form.confirmacao.sim']}" type="button" styleClass="ui-confirmdialog-yes" />
<p:commandButton icon="ui-icon-close" value="#{text['arquivo.pagina.form.confirmacao.nao']}" type="button" styleClass="ui-confirmdialog-no" />
</p:confirmDialog>
</p:column>
</p:dataTable>
<p:dialog id="arquivo-detalhes" widgetVar="arquivoDialog">
<h:panelGrid columns="2" cellpadding="4" style="margin:0 auto;">
<h:outputLabel value="#{text['arquivo.pagina.form.id']}:" />
<h:outputText value="#{arquivoBean.objeto.id}" />
<h:outputLabel value="#{text['arquivo.pagina.form.arquivo']}:" />
<h:graphicImage value="../../arquivos/#{arquivoBean.objeto.nome}" width="200" rendered="#{arquivoBean.isImagem()}" />
<p:media value="../../arquivos/#{arquivoBean.objeto.nome}" width="200" height="80" player="quicktime" rendered="#{arquivoBean.isAudio()}" />
<p:media value="../../arquivos/#{arquivoBean.objeto.nome}" width="300" height="300" rendered="#{arquivoBean.isVideo()}"/>
</h:panelGrid>
</p:dialog>
</h:form>
<p:dialog id="arquivoTransferirDialog" widgetVar="arquivoTransferirDialog">
<h:form id="formArquivoTransferir">
<p:growl id="msg" showDetail="false"/>
<h:panelGrid columns="1">
<p:tree id="treeArquivos" value="#{arquivoBean.raiz}" var="arquivo" selection="#{arquivoBean.raizSelecionada}" selectionMode="single">
<p:treeNode expandedIcon="ui-icon ui-icon-folder-open" collapsedIcon="ui-icon ui-icon-folder-collapsed">
<h:outputText value="#{arquivo.nomeOriginal}" />
</p:treeNode>
</p:tree>
<h:panelGrid columns="2">
<p:commandButton value="Transferir" actionListener="#{arquivoBean.transferirArquivo()}" oncomplete="PF('arquivoTransferirDialog').hide()" update="formArquivoTransferir, :form-arquivo-listar:dataArquivos"/>
<p:commandButton value="Cancelar" onclick="PF('arquivoTransferirDialog').hide()"/>
</h:panelGrid>
</h:panelGrid>
</h:form>
</p:dialog>
<p:dialog id="arquivoCriarPasta" widgetVar="arquivoCriarPasta">
<h:form id="formCriarPasta">
<p:growl id="msg" showDetail="false"/>
<h:panelGrid columns="2">
<h:outputText value="Nome" />
<p:inputText value="#{arquivoBean.objeto.nomeOriginal}" required="true"/>
<h:column/>
<h:panelGrid columns="2">
<p:commandButton value="Salvar" actionListener="#{arquivoBean.salvarPasta()}" update="formCriarPasta,:form-arquivo-listar:dataArquivos" oncomplete="PF('arquivoCriarPasta').hide()"/>
<p:commandButton value="Cancelar" onclick="PF('arquivoCriarPasta').hide()"/>
</h:panelGrid>
</h:panelGrid>
</h:form>
</p:dialog>
<p:dialog id="cadastroArquivo" header="#{text['arquivo.pagina.editar.titulo']}" widgetVar="cadastroArquivo" >
<h:form id="form-arquivo-editar" enctype="multipart/form-data">
<p:growl id="msg" showDetail="false"/>
<h:inputHidden value="#{arquivoBean.objeto.id}" rendered="#{arquivoBean.objeto.id!=null}" />
<h:panelGrid columns="2" style="margin:20px">
<p:outputLabel value="#{text['arquivo.pagina.form.arquivo']}" for="inputArquivo" />
<p:fileUpload id="inputArquivo" value="#{arquivoBean.file}" required="true" label="#{text['arquivo.pagina.form.arquivo']}" mode="simple"
disabled="#{arquivoBean.objeto.id!=null and arquivoBean.objeto.id!=0}" />
<p:outputLabel value="#{text['arquivo.pagina.form.nome']}" rendered="#{arquivoBean.objeto.id!=null and arquivoBean.objeto.id!=0}" />
<h:outputText value="#{arquivoBean.objeto.nomeOriginal}" rendered="#{arquivoBean.objeto.id!=null and arquivoBean.objeto.id!=0}" />
<p:outputLabel value="#{text['arquivo.pagina.form.descricao']}" for="inputDescricao" />
<p:inputTextarea id="inputDescricao" value="#{arquivoBean.objeto.descricao}" />
<p:outputLabel value="#{text['arquivo.pagina.form.publico']}" for="inputPublico" />
<p:selectBooleanCheckbox id="inputPublico" value="#{arquivoBean.objeto.publico}" />
<p:outputLabel value="#{text['arquivo.pagina.form.tipo']}" for="inputTipo" />
<p:selectOneMenu id="inputTipo" value="#{arquivoBean.objeto.tipo}" required="true" label="#{text['arquivo.pagina.form.tipo']}"
converter="#{arquivoTipoBean.converter()}">
<f:selectItem itemLabel="#{text['arquivo.pagina.form.tipo.default']}" />
<f:selectItems value="#{arquivoTipoBean.selectObjetos}" />
</p:selectOneMenu>
</h:panelGrid>
<h:panelGrid columns="2" style="margin-bottom:10px">
<p:commandButton value="#{text['arquivo.pagina.form.salvar']}" update=":form-arquivo-editar,:form-arquivo-listar"
process="#form" actionListener="#{arquivoBean.salvar}" ajax="false" />
</h:panelGrid>
</h:form>
</p:dialog>

How to tell if pressed YES or NO in a confirm dialog with Primefaces?

the method remove is called either I click YES or NO.
How can I tell if NO is pressed ?
<p:commandLink actionListener="#{mybean.remove}"
ajax="false"
>
<p:confirm header="Confirm" message="Are you sure?" icon="ui-icon-alert"></p:confirm> <h:graphicImage value="images/erasebig.png" />
</p:commandLink>
<p:confirmDialog id="dialog" global="true" showEffect="fade" hideEffect="explode" message="Are you sure?">
<p:commandButton value="Yes" type="button"
styleClass="ui-confirmdialog-yes" icon="ui-icon-check"
/>
<p:commandButton value="No" type="button" styleClass="ui-confirmdialog-yes" icon="ui-icon-close" />
</p:confirmDialog>
Put styleClass="ui-confirmdialog-no" on the no-button and mybean.remove() wont be called

Resources