1
I have a list and I need to send it to another page to fill a table, when the redirect ends the page loads only the table does not fill because the list has been emptied, as I keep it with the information?
Minhabean
@ManagedBean(name = "lotesEnvBean")
@ViewScoped
public class LoteEnviadoBean implements Serializable {
private static final long serialVersionUID = 1L;
@Inject
private LoteEnvRepository envRepository;
private List<LoteEnvEntity> lotesEnviados;
private List<LoteEnvEntity> lotesSelecionados = new ArrayList<LoteEnvEntity>();
private List<LoteEnvDetalheEntity> lotesEnvDetalhe;
private Collection<Object> selecao;
private Date dataDe;
private Date dataAte;
private Flash flash;
private UIComponent component;
@PostConstruct
public void init() {
this.lotesEnviados = envRepository.findall();
}
public void selectionListener(AjaxBehaviorEvent event) {
AbstractExtendedDataTable dataTable = (AbstractExtendedDataTable) event
.getComponent();
Object originalKey = dataTable.getRowKey();
lotesSelecionados.clear();
for (Object selectionKey : selecao) {
dataTable.setRowKey(selectionKey);
if (dataTable.isRowAvailable()) {
lotesSelecionados.add((LoteEnvEntity) dataTable.getRowData());
}
}
dataTable.setRowKey(originalKey);
}
public Collection<Object> getSelecao() {
return selecao;
}
public void setSelecao(Collection<Object> selecao) {
this.selecao = selecao;
}
public void setSelectionItems(List<LoteEnvEntity> selectionItems) {
this.lotesSelecionados = selectionItems;
}
public List<LoteEnvEntity> getLotesEnviados() {
return lotesEnviados;
}
public void setLotesEnviados(List<LoteEnvEntity> lotesEnviados) {
this.lotesEnviados = lotesEnviados;
}
public List<LoteEnvEntity> getLotesSelecionados() {
return lotesSelecionados;
}
public Date getDataDe() {
return dataDe;
}
public void setDataDe(Date dataDe) {
this.dataDe = dataDe;
}
public Date getDataAte() {
return dataAte;
}
public void setDataAte(Date dataAte) {
this.dataAte = dataAte;
}
public void setLotesSelecionados(List<LoteEnvEntity> lotesSelecionados) {
this.lotesSelecionados = lotesSelecionados;
}
public List<LoteEnvDetalheEntity> getLotesEnvDetalhe() {
return lotesEnvDetalhe;
}
public void setLotesEnvDetalhe(List<LoteEnvDetalheEntity> lotesEnvDetalhe) {
this.lotesEnvDetalhe = lotesEnvDetalhe;
}
public UIComponent getComponent() {
return component;
}
public void setComponent(UIComponent component) {
this.component = component;
}
public Flash getFlash() {
return flash;
}
public void setFlash(Flash flash) {
this.flash = flash;
}
public List<LoteEnvEntity> findByDate() {
this.lotesEnviados = envRepository.findallByDate(this.dataDe,
this.dataAte);
return this.lotesEnviados;
}
public String exibirLotesSelecionados() {
FacesContext context = FacesContext.getCurrentInstance();
System.out.println("#########################################################----" + this.lotesSelecionados.size());
if(this.lotesSelecionados.size() <= 0) {
context.addMessage(component.getClientId(), new FacesMessage(FacesMessage.SEVERITY_ERROR, "Erro","Deve-se selecionar ao menos um lote."));
return "";
}
this.lotesEnvDetalhe = this.envRepository.exibirLotesSelecionados(this.lotesSelecionados);
if (this.lotesEnvDetalhe.size() > 0)
return "lotesEnviadosListagem.xhtml?faces-redirect=true";
else
context.addMessage(component.getClientId(), new FacesMessage(FacesMessage.SEVERITY_ERROR, "Erro","Não foi possível exibir o(s) lote(s)."));
return "";
}
}
}
I started working with Java EE this week, before that I had little contact with web development, and I’m having to jump in here. In this case by using Flashcontet then?
– João
Where’s your bean Managed?? Just put the gets and sets on it and refer it to the page
– yehiaazanki
You can use the
FacesContext.getInstance().getExternalContext().getFlash()
to access theFlash Scope
. Access both before redirect to send the list, and onPostConstruct
to retrieve it.– Wakim
@Wakim thanks! would have an XD example?
– João