You've blocked GET, so <redirect>
is definitely not going to work as it actually creates a new GET request. See also What is the difference between redirect and navigation/forward and when to use what?
What can you do? If it's really not an option to conditionally render results in the very same view by using includes and such (so that you can just keep using the same view scoped bean instance), then you should just perform a POST navigation without a redirect. You probably already figured that a navigation will immediately destroy any view scoped beans tied to the current view before the new view is created. Hence it's not possible to just do a @ManagedProperty
of "previous" view scoped bean in the "current" view scoped bean. It'll give you a brand new instance without the original properties.
However, as the POST navigation without a redirect happens all in the very same request, you actually don't need to pass the data along in the session scope at all, it would work as good via the request scope. You just have to grab it immediately in the @PostConstruct
of the view scoped bean associated with the target page. This data is definitely not shared in other requests.
Basically the process can go as follows (backing bean and property names are just educated guesses based on information provided so far):
<h:dataTable value="#{ranking.persons}" var="person">
<h:column>#{person.id}</h:column>
<h:column>#{person.name}</h:column>
<h:column>#{person.email}</h:column>
<h:column><h:commandButton value="edit" action="#{ranking.editPerson(person)}" /></h:column>
</h:dataTable>
@ManagedBean(name="ranking")
@ViewScoped
public class RankingBacking implements Serializable {
private List<Person> persons;
public String editPerson(Person person) {
ExternalContext ec = FacesContext.getCurrentInstance().getExternalContext();
ec.getRequestMap().put("person", person);
return "editPerson";
}
// ...
}
@ManagedBean(name="person")
@ViewScoped
public class PersonBacking implements Serializable {
private Person current;
@PostConstruct
public void init() {
ExternalContext ec = FacesContext.getCurrentInstance().getExternalContext();
current = (Person) ec.getRequestMap().get("person");
}
// ...
}
<h:outputText value="#{person.current.id}" />
<h:inputText value="#{person.current.name}" />
<h:inputText value="#{person.current.email}" />
...
<h:commandButton value="Save" ... />