Flash スコープ変数を設定してからリダイレクトしようとすると、Flash スコープで問題が発生します。コンソールで、次のトレースを取得します...
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.
アイデアは、最初のページ (検索ページ) から 2 番目のページに ID を渡すことですが、immediate を使用してキャンセルすると、前述のログが取得され、フラッシュ カウンターはそれ以上増加しません。
コード:
(検索ビーン) @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;
}
}
(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;
}
}
私はあなたの助けに感謝します。