1

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>`
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
user2683519
  • 747
  • 5
  • 11
  • 19

1 Answers1

3

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);
}
noone
  • 19,520
  • 5
  • 61
  • 76