voyent
clear request scoped bean from extended request scope  XML
Forum Index -> Contributor's Corner
Author Message
garry.donnelly

Joined: 10/May/2009 00:00:00
Messages: 13
Offline


Hi

I've written a method to clear a request scoped bean from extended request scope and I was wondering if I could get feedback on if it will work for others. I am using it to control the state of certain pages in my workflow allowing me to have some pages work as if they are not under extended request scope.

Code:
     protected void removeIceFacesExtendedRequestScopeBean(String managedBeanName) {
 
         Object bean = getBean(managedBeanName);
         
         if (bean instanceof DisposableBean) {
             try {
                 ((DisposableBean) bean).dispose();
             } catch (Exception e) {
                 log("Failed to properly dispose " + bean + " bean.", e);
             }
         }
 
         setBean(managedBeanName, null);
         getExternalContext().getRequestMap().remove(managedBeanName);
 }
 


Code:
     protected Object getBean(String name) {
 
         return getApplication().getELResolver().getValue(getELContext(), null, name);
 
     }
 


Code:
     protected void setBean(String name, Object value) {
 
         getApplication().getELResolver().setValue(getELContext(), null, name, value);
     }
 


Code:
     protected Application getApplication() {
 
         return FacesContext.getCurrentInstance().getApplication();
 
     }
 


Code:
     protected ELContext getELContext() {
         return getFacesContext().getELContext();
     }
 


Code:
     protected ExternalContext getExternalContext() {
 
         return FacesContext.getCurrentInstance().getExternalContext();
 
     }
 


Code:
     protected FacesContext getFacesContext() {
 
         return FacesContext.getCurrentInstance();
 
     }
 


Any feedback much appreciated. I have yet to test this with concurrent dom so that should be interesting.
wrschneider99

Joined: 19/Mar/2010 00:00:00
Messages: 14
Offline


I would appreciate a clearer picture of how extended request scope actually works - where do the elements actually live in the session or request attributes? Or is this something internal to ICEfaces we're just not supposed to play with directly?

I did find that the right magic is:
Code:
 fcontext.getExternalContext().getRequestMap().remove(beanName)
 


The ELResolver.setValue(null) call by itself doesn't actually work, and has the consequence that the bean is returned as null to EL expressions in the JSPX page on reload, but does not get re-initialized.

I also found that the ELResolver.setValue(null) call has a consequence of initializing the bean before you actually use or reference it, which may not be what you want the first time you're loading or initializing a page.
 
Forum Index -> Contributor's Corner
Go to:   
Powered by JForum 2.1.7ice © JForum Team