You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by lo...@apache.org on 2012/11/21 09:10:02 UTC

svn commit: r1412008 - in /myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo: NavigationState.java NavigationTree.java SynchronizeNavigationPhaseListener.java

Author: lofwyr
Date: Wed Nov 21 08:10:01 2012
New Revision: 1412008

URL: http://svn.apache.org/viewvc?rev=1412008&view=rev
Log:
optimize tree marker synchronisation

Modified:
    myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/NavigationState.java
    myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/NavigationTree.java
    myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/SynchronizeNavigationPhaseListener.java

Modified: myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/NavigationState.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/NavigationState.java?rev=1412008&r1=1412007&r2=1412008&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/NavigationState.java (original)
+++ myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/NavigationState.java Wed Nov 21 08:10:01 2012
@@ -28,6 +28,7 @@ import org.slf4j.LoggerFactory;
 
 import javax.annotation.PostConstruct;
 import javax.enterprise.event.Observes;
+import javax.faces.context.FacesContext;
 import javax.inject.Inject;
 import javax.inject.Named;
 import java.io.Serializable;
@@ -47,13 +48,15 @@ public class NavigationState implements 
 
   @PostConstruct
   public void init() {
-    currentNode = tree.getTree().getNextNode();
+    currentNode = tree.findByViewId(FacesContext.getCurrentInstance().getViewRoot().getViewId());
     initState();
   }
 
   private void initState() {
-    state.getMarkedState().setMarked(currentNode.getTreePath());
-    state.getExpandedState().expand(currentNode.getTreePath());
+    if (currentNode != null) {
+      state.getMarkedState().setMarked(currentNode.getTreePath());
+      state.getExpandedState().expand(currentNode.getTreePath());
+    }
   }
 
   public NavigationNode getCurrentNode() {

Modified: myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/NavigationTree.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/NavigationTree.java?rev=1412008&r1=1412007&r2=1412008&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/NavigationTree.java (original)
+++ myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/NavigationTree.java Wed Nov 21 08:10:01 2012
@@ -126,14 +126,18 @@ public class NavigationTree implements S
   }
 
   public void selectByViewId(String viewId) {
+    gotoNode(findByViewId(viewId));
+  }
+
+  public NavigationNode findByViewId(String viewId) {
     Enumeration enumeration = tree.depthFirstEnumeration();
     while (enumeration.hasMoreElements()) {
       NavigationNode node = ((NavigationNode) enumeration.nextElement());
       if (node.getOutcome() != null && viewId.contains(node.getOutcome())) {
-        gotoNode(node);
-        break;
+        return node;
       }
     }
+    return null;
   }
 
   public NavigationNode getTree() {

Modified: myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/SynchronizeNavigationPhaseListener.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/SynchronizeNavigationPhaseListener.java?rev=1412008&r1=1412007&r2=1412008&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/SynchronizeNavigationPhaseListener.java (original)
+++ myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/SynchronizeNavigationPhaseListener.java Wed Nov 21 08:10:01 2012
@@ -27,20 +27,34 @@ import javax.faces.event.PhaseEvent;
 import javax.faces.event.PhaseId;
 import javax.faces.event.PhaseListener;
 
+//todo @JsfPhaseListener
 public class SynchronizeNavigationPhaseListener implements PhaseListener {
 
   public void beforePhase(PhaseEvent event) {
+    if (PhaseId.RENDER_RESPONSE.equals(event.getPhaseId())) {
+      // synchronizing current site with
+      FacesContext facesContext = FacesContext.getCurrentInstance();
+      UIViewRoot viewRoot = facesContext.getViewRoot();
+      // in case of direct links the ViewRoot is empty after "restore view".
+      if (viewRoot != null && viewRoot.getChildCount() == 0) {
+        String viewId = viewRoot.getViewId();
+        NavigationTree navigation = (NavigationTree) VariableResolverUtils.resolveVariable(facesContext, "navigationTree");
+        navigation.gotoNode(navigation.findByViewId(viewId));
+      }
+    }
   }
 
   public void afterPhase(PhaseEvent event) {
-    // synchronizing direct links with controller
-    FacesContext facesContext = FacesContext.getCurrentInstance();
-    UIViewRoot viewRoot = facesContext.getViewRoot();
-    // in case of direct links the ViewRoot is empty after "restore view".
-    if (viewRoot != null && viewRoot.getChildCount() == 0) {
-      String viewId = viewRoot.getViewId();
-     NavigationTree navigation = (NavigationTree) VariableResolverUtils.resolveVariable(facesContext, "navigationTree");
-      navigation.selectByViewId(viewId);
+    if (PhaseId.RESTORE_VIEW.equals(event.getPhaseId())) {
+      // synchronizing direct links with controller
+      FacesContext facesContext = FacesContext.getCurrentInstance();
+      UIViewRoot viewRoot = facesContext.getViewRoot();
+      // in case of direct links the ViewRoot is empty after "restore view".
+      if (viewRoot != null && viewRoot.getChildCount() == 0) {
+        String viewId = viewRoot.getViewId();
+        NavigationTree navigation = (NavigationTree) VariableResolverUtils.resolveVariable(facesContext, "navigationTree");
+        navigation.gotoNode(navigation.findByViewId(viewId));
+      }
     }
   }