How to pass object to another view in JSF?

2

What is the best way to pass an object to another view in JSF?

I have two pages one query and another with the data to edit an object, the query page has a list of objects and each object has the edit button that causes it to redirect to the editing page, I can not send the object and load the edit page. My Bean I'm using ViewScoped.

In other languages it is possible to pass through POST but in java it is a bit complicated I can not adapt. If possible, put a snippet of code.

    
asked by anonymous 06.01.2015 / 18:56

2 answers

1

View Scope ) is dropped whenever navigation from one screen to another occurs.

An alternative is to store the object in the Session scope ( Session Scope ).

You can also pass the object ID a URL parameter or Flash Scope and then load it again on the destination page.

    
06.01.2015 / 19:10
-1

Setting the object in Flash Scope

String str = "teste";

FacesContext.getCurrentInstance().getExternalContext().getFlash().put("teste", str);

In the other Bean create a method and use @PostConstruct annotation.

@PostConstruct
public void init() {
     String strAux = (String) FacesContext.getCurrentInstance().getExternalContext().getFlash().get("teste");
}

You can pass a List.

FacesContext.getCurrentInstance().getExternalContext().getFlash().put(LISTA_STRING, listaString);

@PostConstruct
public void init() {
     List<String> listaString = (List<String>) FacesContext.getCurrentInstance().getExternalContext().getFlash().get(LISTA_STRING);
}
    
21.01.2015 / 19:03