<f:setPropertyActionListener does not work

Asked

Viewed 627 times

1

I have the following xhtml page with the boot "Delete".

<ui:composition template="WEB-INF/templates/_perfil-template.xhtml"
        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">
        <ui:define name="corpo-perfil">
            <h:form id="formulario">
                <div class="botoes-perfil" style="text-align: center;">
                    <p:panel rendered="#{perfilBean.tipoMensagem == 'Entrada'}"
                        header="Mensagens Recebidas" styleClass="barraPainel">
                        <p:dataList var="msg" value="#{perfilBean.mensagemRecebida}"
                            id="mensagens">
                            <p:commandButton value="Deletar" style="color:red;"
                                actionListener="#{mensagemBean.deletar}">
                                <f:setPropertyActionListener value="Testando..."
                                    target="#{mensagemBean.teste}" />
                                <p:confirm header="Deseja mesmo deletar a mensagem?"
                                    message="Esse processo não pode ser desfeito."
                                    icon="ui-icon-alert">
                                </p:confirm>
                            </p:commandButton>

                            <p:confirmDialog global="true" showEffect="fade" hideEffect="fade">
                                <p:commandButton value="Sim" type="button"
                                    styleClass="ui-confirmdialog-yes" icon="ui-icon-check">
//Ja tentei usar o setProperty aqui também.
                                </p:commandButton>
                                <p:commandButton value="Não" type="button"
                                    styleClass="ui-confirmdialog-no" icon="ui-icon-close" />
                            </p:confirmDialog>
                            <p:separator />
                        </p:dataList>
                    </p:panel>
                 </div>
            </h:form>
        </ui:define>
    </ui:composition>

My Bean.

import java.io.IOException;
import java.io.Serializable;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;

import javax.annotation.PostConstruct;
import javax.enterprise.context.RequestScoped;
import javax.faces.view.ViewScoped;
import javax.inject.Inject;
import javax.inject.Named;

import br.com.so.dao.interfacesDao.IMensagemDao;
import br.com.so.dao.interfacesDao.IUsuarioDao;
import br.com.so.modelo.Mensagem;
import br.com.so.modelo.Usuario;
import br.com.so.util.jsf.FacesUtil;

@Named
@ViewScoped
public class MensagemBean implements Serializable {
     private String teste;
     //Getters e Setters.
     public void deletar(){
         System.out.println(teste);  // <--- Aqui sempre imprime null
     }
}


porque sempre o metodo deletar é executado após o confirme dialog mas, o <f:setPropertyActionListener passa o valor null para a String 'teste'?
Ja tentei deixar o dialog fora do dataList, fora do panel, de nenhuma forma estou conseguindo passar o valor para o bean.
Ja tentei também passar o setProperty dentro do commandoButton do confirmDialog com valor 'Sim'.

1 answer

2

Leave these two lines of your xhtml page this way to see if it still returns null in the string.

<p:commandButton value="Deletar" style="color:red;" action="#{mensagemBean.deletar}">

<f:setPropertyActionListener value="#{msg}" target="#{mensagemBean.teste}" />

//Outras linhas de códigos
</p:commandButton>
  • just like that?

  • in button commandButton delete change actionListener for action and in setPropertyActionListener put value like this: value="#{msg}"

Browser other questions tagged

You are not signed in. Login or sign up in order to post.