Flash Scope does not delete variables

492 Views Asked by At

I'm having a problem with Flash Scope when I try to set a flash scope variable and then do a redirect. In the console, I get the following trace...

    com.sun.faces.context.flash.ELFlash setCookie
    WARNING: JSF1095: The response was already committed by the time we tried to set the outgoing     
    cookie for the flash.  Any values stored to the flash will not be available on the next request.

The idea is pass an id from the first page (search page) to the second page, but if I cancel using immediate, I get the mentioned log, and the flash counter is not incremented anymore.

The code:

(Search bean) @ManagedBean @ViewScoped public class ConsultarPaisBean implements Serializable { private static final long serialVersionUID = 7947494818704255376L;

@ManagedProperty("#{flash}")
private Flash flash;

@ManagedProperty("#{paisService}")
private PaisService paisService;

private List<Pais> paises;
private PaisFilter paisFilter;
private Pais paisSelected;

@PostConstruct
public void init() {
    this.paisFilter = new PaisFilter();
    this.paisSelected = null;
    this.paises = null;
}

public String irRegistrarPais() {
    return MappingUrlConstants.PAIS;
}

public String irModificarPais() {
    String respuesta = null;
    if (this.paisSelected != null && this.paisSelected.getId() != null) {
        flash.put("paisId", this.paisSelected.getId());
        respuesta = MappingUrlConstants.PAIS;
    }
    return respuesta;
}

public String buscarPaises() {
    this.paisSelected = null;
    this.paises = this.paisService.getPaisByParams(this.paisFilter);
    return null;
}

public String limpiarFiltros() {
    this.paisFilter = new PaisFilter();
    return null;
}

public List<Pais> getPaises() {
    return paises;
}

public void setPaises(List<Pais> paises) {
    this.paises = paises;
}

public PaisFilter getPaisFilter() {
    return paisFilter;
}

public void setPaisFilter(PaisFilter paisFilter) {
    this.paisFilter = paisFilter;
}

public Pais getPaisSelected() {
    return paisSelected;
}

public void setPaisSelected(Pais paisSelected) {
    this.paisSelected = paisSelected;
}

public void setPaisService(PaisService paisService) {
    this.paisService = paisService;
}

public void setFlash(Flash flash) {
    this.flash = flash;
}

}

(Add/Update bean)

@ManagedBean
@ViewScoped
public class PaisBean implements Serializable {

private static final long serialVersionUID = 3604521826400240955L;

@ManagedProperty("#{paisService}")
private PaisService paisService;

@ManagedProperty("#{flash}")
private Flash flash;

private Pais pais;

@PostConstruct
public void init() {
    if (this.flash.get("paisId") != null) {
        Long id = (Long) this.flash.get("paisId");
        this.pais = this.paisService.getPaisById(id);
    } else {
        this.pais = new Pais();
    }
}

public String registrarPais() {

    String mensajeExito = null;
    if (this.pais.getId() == null) {
        this.paisService.save(this.pais);
        mensajeExito = MessageUtils.getMessage("org.siae.commons.messages.general", "pais.registrar.exito",
                new Object[] { this.pais.getNombre() });
    } else {
        this.paisService.update(this.pais);
        mensajeExito = MessageUtils.getMessage("org.siae.commons.messages.general", "pais.modificar.exito",
                new Object[] { this.pais.getNombre() });
    }
    FacesUtils.addInfoMessage(mensajeExito);
    return MappingUrlConstants.CONSULTAR_PAIS;
}

public String irConsultarPais() {
    return MappingUrlConstants.CONSULTAR_PAIS;
}

public void setPaisService(PaisService paisService) {
    this.paisService = paisService;
}

public void setFlash(Flash flash) {
    this.flash = flash;
}

public Pais getPais() {
    return pais;
}

public void setPais(Pais pais) {
    this.pais = pais;
}

}

I appreciate your help.

0

There are 0 best solutions below