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 10:34:26 UTC

svn commit: r1412026 - in /myfaces/tobago/branches/tobago-1.5.x/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 09:34:25 2012
New Revision: 1412026

URL: http://svn.apache.org/viewvc?rev=1412026&view=rev
Log:
backport from trunk

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

Modified: myfaces/tobago/branches/tobago-1.5.x/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/NavigationState.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/branches/tobago-1.5.x/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/NavigationState.java?rev=1412026&r1=1412025&r2=1412026&view=diff
==============================================================================
--- myfaces/tobago/branches/tobago-1.5.x/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/NavigationState.java (original)
+++ myfaces/tobago/branches/tobago-1.5.x/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/NavigationState.java Wed Nov 21 09:34:25 2012
@@ -25,6 +25,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;
@@ -44,7 +45,7 @@ public class NavigationState implements 
 
   @PostConstruct
   public void init() {
-    currentNode = tree.getTree().getNextNode();
+    currentNode = tree.findByViewId(FacesContext.getCurrentInstance().getViewRoot().getViewId());
     initState();
   }
 

Modified: myfaces/tobago/branches/tobago-1.5.x/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/NavigationTree.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/branches/tobago-1.5.x/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/NavigationTree.java?rev=1412026&r1=1412025&r2=1412026&view=diff
==============================================================================
--- myfaces/tobago/branches/tobago-1.5.x/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/NavigationTree.java (original)
+++ myfaces/tobago/branches/tobago-1.5.x/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/NavigationTree.java Wed Nov 21 09:34:25 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/branches/tobago-1.5.x/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/SynchronizeNavigationPhaseListener.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/branches/tobago-1.5.x/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/SynchronizeNavigationPhaseListener.java?rev=1412026&r1=1412025&r2=1412026&view=diff
==============================================================================
--- myfaces/tobago/branches/tobago-1.5.x/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/SynchronizeNavigationPhaseListener.java (original)
+++ myfaces/tobago/branches/tobago-1.5.x/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/SynchronizeNavigationPhaseListener.java Wed Nov 21 09:34:25 2012
@@ -27,24 +27,35 @@ 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())) {
+      synchronizeState();
+    }
   }
 
   public void afterPhase(PhaseEvent event) {
-    // synchronizing direct links with controller
+    if (PhaseId.RESTORE_VIEW.equals(event.getPhaseId())) {
+      synchronizeState();
+    }
+  }
+
+  public PhaseId getPhaseId() {
+    return PhaseId.ANY_PHASE;
+  }
+
+  private void synchronizeState() {
+    // 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.selectByViewId(viewId);
+      NavigationTree navigation
+          = (NavigationTree) VariableResolverUtils.resolveVariable(facesContext, "navigationTree");
+      navigation.gotoNode(navigation.findByViewId(viewId));
     }
   }
-
-  public PhaseId getPhaseId() {
-    return PhaseId.RESTORE_VIEW;
-  }
 }