问题
My problem is te data is not refresh in the datatable. I want to destroy the session scoped when I clicked to the item in the menu.I know that it's possible with Viewscoped but I want to learn other way. Thank in advanced.
Controller:
@ManagedBean
@SessionScoped
public class MyController implements Serializable {
//getters and setters
...........
}
Menu:
<td><h:outputLink styleClass="itemOutputLink" value="# {request.contextPath}/pages/page.faces">Page1</h:outputLink></td>`
回答1:
There is no really "clean" way of doing that. A @SessionScoped bean should live as long as a Session. Thus I emphasize again that you should better adjust the beans scope.
But if you really still need to do it, the easiest way would be to do it like this:
public static void removeSessionScopedBean(String beanName)
{
FacesContext.getCurrentInstance().getExternalContext().getSessionMap().remove(beanName);
}
For @ViewScoped beans you could do it this way:
public static void removeViewScopedBean(String beanName)
{
FacesContext.getCurrentInstance().getViewRoot().getViewMap().remove(beanName);
}
来源:https://stackoverflow.com/questions/19485391/whats-the-convenient-way-to-destroy-sessionscoped