Flash Scope不会删除变量

时间:2013-01-18 01:01:18

标签: jsf-2 flash-scope

当我尝试设置闪存范围变量然后执行重定向时,我遇到了Flash Scope问题。在控制台中,我得到以下跟踪...

    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.

这个想法是将id从第一页(搜索页面)传递到第二页,但是如果我使用immediate取消,我会得到提到的日志,并且flash计数器不再增加。

代码:

(搜索bean)     @ManagedBean     @ViewScoped     public class ConsultarPaisBean实现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;
}

}

(添加/更新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;
}

}

感谢您的帮助。

0 个答案:

没有答案