You'd need to address backtracking and page refreshing issues as well.

On 10/4/05, Zhong Li <[EMAIL PROTECTED]> wrote:
> Hi All,
>
>  I am trying to find a way to avoid saveState tag on client side, finally I
> got an idea, please give me comments regardless my thought wrong or right.
> Actually it is way to save server side data/model. We define DataSaveManager
> to manage save/remove a data in a session. When code saves data into
> session, sametime need set possible pages the data will be used, or create a
> data path rules. In phaseListener after RENDER_RESPONSE(6), we check the
> data in session, if current viewRoot isn't in possible pages list or data
> path rules list, the data will be removed automatically. Of couse, code can
> remove any data anytime. If the way works, we may find a way to do it in
> config file. We can add possiblePageList in ManageBean defination section
> and pageRuleList in Navigation Rules section.
>
>  Codes looks like
>
>  /**
>   * @author zli
>   *
>  */
>  public class MposPhaseListener implements PhaseListener {
>
>      /* (non-Javadoc)
>       * @see
> javax.faces.event.PhaseListener#afterPhase(javax.faces.event.PhaseEvent)
>       */
>      public void afterPhase(PhaseEvent arg0) {
>
> //System.out.println("afterPhase:"+arg0.getPhaseId());
>          String viewId = arg0.getFacesContext().getViewRoot().getViewId();
>          Map sessionData =
> DataSaveManager.getSessionDataMap();
>          Set removeIds = new HashSet();
>          if( sessionData!=null ){
>              Iterator itr = sessionData.keySet().iterator();
>              while( itr.hasNext() ){
>                  String dataId = (String)itr.next();
>                  SaveData saveData =
> (SaveData)sessionData.get(dataId);
>                  LinkedList possiblePageList =
> saveData.getPossiblePageList();
>                  //we check if the viewId in possible page
>                  if(possiblePageList!=null &&
> possiblePageList.contains(viewId) ){
>                      //we need keep it;
>                      continue;
>                  }
>
>                  LinkedList pageRuleList =  saveData.getPageRuleList();
>                  if( pageRuleList!=null ){
>                      //we check and consume rules
>                      for( int pi = 0;pi<pageRuleList.size();pi++ ){
>                          //try one rule
>                          LinkedList rulePath =
> (LinkedList)pageRuleList.get(pi);
>                          if( rulePath.contains(viewId) ){
>                              if( viewId.equals(rulePath.get(0)) ){//cosume
> it
>                                  rulePath.remove(0);//cosumed.
>                                  //we need keep it;
>                                  continue;
>                              }
>                          }
>                      }
>                  }
>                  //this data is useless, put in removeIds
>                  removeIds.add(dataId);
>              }
>              //remove data
>              itr = removeIds.iterator();
>              while(itr.hasNext()){
>                  String dataId = (String)itr.next();
>                  sessionData.remove(dataId);
>              }
>
>          }
>
>      }
>
>      /* (non-Javadoc)
>       * @see
> javax.faces.event.PhaseListener#beforePhase(javax.faces.event.PhaseEvent)
>       */
>      public void beforePhase(PhaseEvent arg0) {
>
> //System.out.println("beforePhase:"+arg0.getPhaseId());
>      }
>
>      /* (non-Javadoc)
>       * @see javax.faces.event.PhaseListener#getPhaseId()
>       */
>      public PhaseId getPhaseId() {
>          return PhaseId.RENDER_RESPONSE;
>          //return PhaseId.ANY_PHASE;
>      }
>
>  }
>
>
>  public class DataSaveManager{
>      public final static String
> sessionID="_DATA_SAVE_SESSION_ENTRY";
>      public static Map getSessionDataMap(){
>          FacesContext context = FacesContext.getCurrentInstance();
>          ExternalContext ext = context.getExternalContext();
>          return (Map)ext.getSessionMap().get(sessionID);
>      }
>
>      /**
>       *
>       * @param data
>       * @param possiblePageList  is LinkedList
>       * @param pageRuleList is LinkedList wrap of LinkedList
>       */
>      public static void saveData(String dataId, Object data, LinkedList
> possiblePageList, LinkedList pageRuleList){
>          getSessionDataMap().put(dataId,new
> SaveData(dataId,data, possiblePageList, pageRuleList));
>      }
>      public static void removeData(String dataId){
>          getSessionDataMap().remove(dataId);
>      }
>      public static SaveData getSaveData(String dataId){
>          return (SaveData)getSessionDataMap().get(dataId);
>      }
>
>  }
>
>
>  public class SaveData{
>      String dataId;
>      Object data;
>      LinkedList possiblePageList;
>      LinkedList pageRuleList;
>      public SaveData(String dataId, Object data, LinkedList
> possiblePageList, LinkedList pageRuleList){
>          this.dataId = dataId;
>          this.data = data;
>          this.possiblePageList = possiblePageList;
>          this.pageRuleList = pageRuleList;
>      }
>      public Object getData(){
>          return data;
>      }
>      public LinkedList getPossiblePageList(){
>          return possiblePageList;
>      }
>      public LinkedList getPageRuleList(){
>          return pageRuleList;
>      }
>      public String getDataId(){
>          return dataId;
>      }
>  }
>
>
>
>  If this is possible, so we can make it in JSF1.2, it will solve lots
> problems.
>
>
> --
> Zhong Li
>
> WebJabber.Net

Reply via email to