How to clean up bean from session when using facelets? I need to remove bean if the request contains cleanupFlag parameter.
When I used JSP I did it with this small _javascript_let at the begining of the page.

<jsp: directive.page
  import="javax.faces.context.FacesContext,javax.faces.component.UIViewRoot,javax.faces.application.ViewHandler"
  contentType="text/html;charset=iso-8859-1"
  buffer="64kb"/>
  <jsp:scriptlet>
       if(request.getParameter("cleanupFlag") != null) {
          FacesContext.getCurrentInstance().getExternalContext().getSessionMap().remove("formBean"); {
          // recreate view
         FacesContext facesContext = FacesContext.getCurrentInstance();
         facesContext.getApplication().createValueBinding("#{formBeanId}").setValue(facesContext, null);
         ViewHandler viewHandler = facesContext.getApplication().getViewHandler();
         UIViewRoot newRoot = viewHandler.createView(facesContext, facesContext.getViewRoot().getViewId());
         facesContext.setViewRoot (newRoot);
        }
      }
 </jsp:scriptlet>

Thanks, --MG


Reply via email to