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 2007/01/26 21:01:23 UTC

svn commit: r500319 - in /myfaces/tobago/trunk/example/demo/src/main: java/org/apache/myfaces/tobago/example/demo/Navigation.java java/org/apache/myfaces/tobago/example/demo/SynchronizeNavigationPhaseListener.java webapp/WEB-INF/faces-config.xml

Author: lofwyr
Date: Fri Jan 26 12:01:23 2007
New Revision: 500319

URL: http://svn.apache.org/viewvc?view=rev&rev=500319
Log:
SychronizeNavigationPhaseListener is needed to update the Navigation Tree when using direct links.

Added:
    myfaces/tobago/trunk/example/demo/src/main/java/org/apache/myfaces/tobago/example/demo/SynchronizeNavigationPhaseListener.java
      - copied, changed from r500000, myfaces/tobago/trunk/example/demo/src/main/java/org/apache/myfaces/tobago/example/demo/overview/SynchronizeNavigationPhaseListener.java
Modified:
    myfaces/tobago/trunk/example/demo/src/main/java/org/apache/myfaces/tobago/example/demo/Navigation.java
    myfaces/tobago/trunk/example/demo/src/main/webapp/WEB-INF/faces-config.xml

Modified: myfaces/tobago/trunk/example/demo/src/main/java/org/apache/myfaces/tobago/example/demo/Navigation.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/example/demo/src/main/java/org/apache/myfaces/tobago/example/demo/Navigation.java?view=diff&rev=500319&r1=500318&r2=500319
==============================================================================
--- myfaces/tobago/trunk/example/demo/src/main/java/org/apache/myfaces/tobago/example/demo/Navigation.java (original)
+++ myfaces/tobago/trunk/example/demo/src/main/java/org/apache/myfaces/tobago/example/demo/Navigation.java Fri Jan 26 12:01:23 2007
@@ -31,6 +31,7 @@
 import java.io.InputStreamReader;
 import java.io.PrintWriter;
 import java.io.IOException;
+import java.util.Enumeration;
 
 /**
  * User: lofwyr
@@ -78,6 +79,18 @@
   public String navigate() {
     Node selected = (Node) state.getMarker().getUserObject();
     return selected.getOutcome();
+  }
+
+  public void updateMarker(String viewId) {
+    Enumeration enumeration = tree.depthFirstEnumeration();
+    while (enumeration.hasMoreElements()) {
+      DefaultMutableTreeNode maybeMarker = ((DefaultMutableTreeNode) enumeration.nextElement());
+      Node node = (Node) maybeMarker.getUserObject();
+      if (viewId.contains(node.getOutcome())) {
+        state.setMarker(maybeMarker);
+        break;
+      }
+    }
   }
 
   public DefaultMutableTreeNode getTree() {

Copied: myfaces/tobago/trunk/example/demo/src/main/java/org/apache/myfaces/tobago/example/demo/SynchronizeNavigationPhaseListener.java (from r500000, myfaces/tobago/trunk/example/demo/src/main/java/org/apache/myfaces/tobago/example/demo/overview/SynchronizeNavigationPhaseListener.java)
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/example/demo/src/main/java/org/apache/myfaces/tobago/example/demo/SynchronizeNavigationPhaseListener.java?view=diff&rev=500319&p1=myfaces/tobago/trunk/example/demo/src/main/java/org/apache/myfaces/tobago/example/demo/overview/SynchronizeNavigationPhaseListener.java&r1=500000&p2=myfaces/tobago/trunk/example/demo/src/main/java/org/apache/myfaces/tobago/example/demo/SynchronizeNavigationPhaseListener.java&r2=500319
==============================================================================
--- myfaces/tobago/trunk/example/demo/src/main/java/org/apache/myfaces/tobago/example/demo/overview/SynchronizeNavigationPhaseListener.java (original)
+++ myfaces/tobago/trunk/example/demo/src/main/java/org/apache/myfaces/tobago/example/demo/SynchronizeNavigationPhaseListener.java Fri Jan 26 12:01:23 2007
@@ -1,4 +1,4 @@
-package org.apache.myfaces.tobago.example.demo.overview;
+package org.apache.myfaces.tobago.example.demo;
 
 /*
  * Licensed to the Apache Software Foundation (ASF) under one or more
@@ -17,11 +17,9 @@
  * limitations under the License.
  */
 
-/*
- * Created 02.06.2004 13:48:46.
- * $Id: SynchronizeNavigationPhaseListener.java 1226 2005-04-21 10:18:15 +0200 (Do, 21 Apr 2005) lofwyr $
- */
+import org.apache.myfaces.tobago.util.VariableResolverUtil;
 
+import javax.faces.component.UIViewRoot;
 import javax.faces.context.FacesContext;
 import javax.faces.event.PhaseEvent;
 import javax.faces.event.PhaseId;
@@ -35,17 +33,12 @@
   public void afterPhase(PhaseEvent event) {
     // synchronizing direct links with controller
     FacesContext facesContext = FacesContext.getCurrentInstance();
-    String viewId = facesContext.getViewRoot().getViewId();
-    String navigationBeanName;
-    if (viewId.indexOf("overview") > -1) {
-      navigationBeanName = "overviewNavigation";
-    } else {
-      // other pages
-      return;
+    UIViewRoot viewRoot = facesContext.getViewRoot();
+    if (viewRoot.getChildCount() == 0) { // in case of direct links the ViewRoot is empty after "restore view".
+      String viewId = viewRoot.getViewId();
+      Navigation navigation = (Navigation) VariableResolverUtil.resolveVariable(facesContext, "navigation");
+      navigation.updateMarker(viewId);
     }
-    PresentationController navigation = PresentationController
-        .getCurrentInstance(facesContext, navigationBeanName);
-    navigation.navigate(viewId);
   }
 
   public PhaseId getPhaseId() {

Modified: myfaces/tobago/trunk/example/demo/src/main/webapp/WEB-INF/faces-config.xml
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/example/demo/src/main/webapp/WEB-INF/faces-config.xml?view=diff&rev=500319&r1=500318&r2=500319
==============================================================================
--- myfaces/tobago/trunk/example/demo/src/main/webapp/WEB-INF/faces-config.xml (original)
+++ myfaces/tobago/trunk/example/demo/src/main/webapp/WEB-INF/faces-config.xml Fri Jan 26 12:01:23 2007
@@ -56,6 +56,9 @@
 
   <lifecycle>
     <phase-listener>
+      org.apache.myfaces.tobago.example.demo.SynchronizeNavigationPhaseListener
+    </phase-listener>
+    <phase-listener>
       org.apache.myfaces.tobago.util.DebugPhaseListener
     </phase-listener>
   </lifecycle>