You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@myfaces.apache.org by mfaine <mf...@knology.net> on 2005/02/24 16:25:28 UTC

resetting beans

The main bean in my application is responsible for listing documents and is
scoped request so that it will always be up to date.  The bean that is used
to edit one of these documents is dependent on the document type and are all
scoped session.  

Currently I'm using this rather hackish device to reset the session scoped
bean:  

In the session scoped (editing) bean's init method I set the bean's name in
a session cache bean.
SessionBean sbean = ( SessionBean ) FacesUtils.getManagedBean ( BeanNames.
        SESSION_BEAN );
sbean.setCurrentBeanName ( BeanNames.NASAGENERAL_BEAN );

Then in my main listing bean's init method: 

SessionBean sbean = (SessionBean)
FacesUtils.getManagedBean(BeanNames.SESSION_BEAN);
DocumentBean bean  = (DocumentBean)
FacesUtils.getManagedBean(sbean.getCurrentBeanName());
    if(bean != null){
      FacesUtils.resetManagedBean(sbean.getCurrentBeanName());
    }

The reason this is necessary is to ensure that when a user selects document
2 they get document 2 and not the last document that was edited.

This works and allows me to reset the managed bean but I'm sure it is not
the best way to do this.

Suggestions and comments appreciated.

Thanks,
-Mark