dev@javaserverfaces.java.net

[REVIEW] Update NavigationHandlerImpl to produce warnings when no navigation case is matched

From: Ryan Lubke <Ryan.Lubke_at_Sun.COM>
Date: Thu, 03 Nov 2005 10:12:49 -0800

Add warning messages to NavigationHandler to provide feedback when
a matching navication case could not be found for a particular
fromViewId/outcome/action combination.

SECTION: Modified Files
----------------------------
M src/com/sun/faces/LogStrings.properties
  - add new messages

M src/com/sun/faces/application/ApplicationAssociate.java
  - Generify getNavigationCaseListMappings()

M src/com/sun/faces/application/NavigationHandlerImpl.java
  - Added warnings when no navigation case could be matched.
  - updated determineViewFromActionOutcome to loop though
    the case list once instead of four times


SECTION: Diffs
----------------------------
Index: src/com/sun/faces/LogStrings.properties
===================================================================
RCS file:
/cvs/javaserverfaces-sources/jsf-ri/src/com/sun/faces/LogStrings.properties,v
retrieving revision 1.3
diff -u -r1.3 LogStrings.properties
--- src/com/sun/faces/LogStrings.properties 22 Aug 2005 22:10:06
-0000 1.3
+++ src/com/sun/faces/LogStrings.properties 3 Nov 2005 18:08:05 -0000
@@ -33,6 +33,8 @@
 jsf.redirect_failed_error=JSF1008: Redirect to path {0} failed
 jsf.faces_servlet_mapping_cannot_be_determined_error=JSF1009: Unable to
determine FaceServlet mapping for servlet path {0}.
 jsf.illegal_view_id_error=JSF1010: Illegal view ID {0}. The ID must
begin with ''/''
+jsf.navigation.no_matching_outcome="JSF1012: Unable to find matching
navigation case from view ID ''{0}'' for outcome ''{1}''
+jsf.navigation.no_matching_outcome_action="JSF1013: Unable to find
matching navigation case from view ID ''{0}'' for outcome ''{1}'' and
action ''{2}''
 
 # core tags
 jsf.core.tags.eval_result_not_expected_type=JSF1011: Evaluation of
expression for attribute ''{0}'' resulted in unexpected type. Expected
{1}, but received {2}.
Index: src/com/sun/faces/application/ApplicationAssociate.java
===================================================================
RCS file:
/cvs/javaserverfaces-sources/jsf-ri/src/com/sun/faces/application/ApplicationAssociate.java,v
retrieving revision 1.22
diff -u -r1.22 ApplicationAssociate.java
--- src/com/sun/faces/application/ApplicationAssociate.java 30 Sep
2005 03:57:19 -0000 1.22
+++ src/com/sun/faces/application/ApplicationAssociate.java 3 Nov
2005 18:08:05 -0000
@@ -340,9 +340,9 @@
      *
      * @return Map the map of navigation mappings.
      */
- public Map getNavigationCaseListMappings() {
+ public Map<String,List<ConfigNavigationCase>>
getNavigationCaseListMappings() {
         if (caseListMap == null) {
- return Collections.EMPTY_MAP;
+ return Collections.emptyMap();
         }
         return caseListMap;
     }
Index: src/com/sun/faces/application/NavigationHandlerImpl.java
===================================================================
RCS file:
/cvs/javaserverfaces-sources/jsf-ri/src/com/sun/faces/application/NavigationHandlerImpl.java,v
retrieving revision 1.40
diff -u -r1.40 NavigationHandlerImpl.java
--- src/com/sun/faces/application/NavigationHandlerImpl.java 26 Aug
2005 15:26:59 -0000 1.40
+++ src/com/sun/faces/application/NavigationHandlerImpl.java 3 Nov
2005 18:08:05 -0000
@@ -177,7 +177,7 @@
     private CaseStruct getViewId(FacesContext context, String fromAction,
                                  String outcome) {
         String viewId = context.getViewRoot().getViewId();
- CaseStruct caseStruct = null;
+ CaseStruct caseStruct;
 
         synchronized (this) {
             caseStruct = findExactMatch(viewId, fromAction, outcome);
@@ -190,6 +190,18 @@
                 caseStruct = findDefaultMatch(fromAction, outcome);
             }
         }
+
+ if (caseStruct == null && logger.isLoggable(Level.WARNING)) {
+ if (fromAction == null) {
+ logger.log(Level.WARNING,
+ "jsf.navigation.no_matching_outcome",
+ new Object[] {viewId, outcome});
+ } else {
+ logger.log(Level.WARNING,
+ "jsf.navigation.no_matching_outcome_action",
+ new Object[] {viewId, outcome, fromAction});
+ }
+ }
         return caseStruct;
     }
 
@@ -217,10 +229,11 @@
     }
         
 
- Map caseListMap = associate.getNavigationCaseListMappings();
+ Map<String,List<ConfigNavigationCase>> caseListMap =
+ associate.getNavigationCaseListMappings();
         assert (null != caseListMap);
 
- List caseList = (List) caseListMap.get(viewId);
+ List<ConfigNavigationCase> caseList = caseListMap.get(viewId);
 
         if (caseList == null) {
             return null;
@@ -260,9 +273,11 @@
         return null;
     }
 
- Map caseListMap = associate.getNavigationCaseListMappings();
+ Map<String,List<ConfigNavigationCase>> caseListMap =
+ associate.getNavigationCaseListMappings();
         assert (null != caseListMap);
- TreeSet<String> wildcardMatchList =
associate.getNavigationWildCardList();
+ TreeSet<String> wildcardMatchList =
+ associate.getNavigationWildCardList();
         assert (null != wildcardMatchList);
 
         for (String fromViewId : wildcardMatchList) {
@@ -279,7 +294,7 @@
             // Append the trailing "*" so we can do our map lookup;
 
             String wcFromViewId = fromViewId + "*";
- List caseList = (List) caseListMap.get(wcFromViewId);
+ List<ConfigNavigationCase> caseList =
caseListMap.get(wcFromViewId);
 
             if (caseList == null) {
                 return null;
@@ -321,10 +336,11 @@
         return null;
     }
 
- Map caseListMap = associate.getNavigationCaseListMappings();
+ Map<String,List<ConfigNavigationCase>> caseListMap =
+ associate.getNavigationCaseListMappings();
         assert (null != caseListMap);
 
- List caseList = (List) caseListMap.get("*");
+ List<ConfigNavigationCase> caseList = caseListMap.get("*");
 
         if (caseList == null) {
             return null;
@@ -351,19 +367,15 @@
      */
 
     private synchronized
- CaseStruct determineViewFromActionOutcome(List caseList,
+ CaseStruct
determineViewFromActionOutcome(List<ConfigNavigationCase> caseList,
                                               String fromAction,
                                               String outcome) {
-
- String cncFromAction = null;
- String fromOutcome = null;
- String toViewId = null;
+
         CaseStruct result = new CaseStruct();
- for (int i = 0; i < caseList.size(); i++) {
- ConfigNavigationCase cnc = (ConfigNavigationCase)
caseList.get(i);
- cncFromAction = cnc.getFromAction();
- fromOutcome = cnc.getFromOutcome();
- toViewId = cnc.getToViewId();
+ for (ConfigNavigationCase cnc : caseList) {
+ String cncFromAction = cnc.getFromAction();
+ String fromOutcome = cnc.getFromOutcome();
+ String toViewId = cnc.getToViewId();
             if ((cncFromAction != null) && (fromOutcome != null)) {
                 if ((cncFromAction.equals(fromAction)) &&
                     (fromOutcome.equals(outcome))) {
@@ -372,27 +384,15 @@
                     return result;
                 }
             }
- }
-
- for (int i = 0; i < caseList.size(); i++) {
- ConfigNavigationCase cnc = (ConfigNavigationCase)
caseList.get(i);
- cncFromAction = cnc.getFromAction();
- fromOutcome = cnc.getFromOutcome();
- toViewId = cnc.getToViewId();
- if ((cncFromAction == null) && (fromOutcome != null)) {
+
+ if ((cncFromAction == null) && (fromOutcome != null)) {
                 if (fromOutcome.equals(outcome)) {
                     result.viewId = toViewId;
                     result.navCase = cnc;
                     return result;
                 }
             }
- }
-
- for (int i = 0; i < caseList.size(); i++) {
- ConfigNavigationCase cnc = (ConfigNavigationCase)
caseList.get(i);
- cncFromAction = cnc.getFromAction();
- fromOutcome = cnc.getFromOutcome();
- toViewId = cnc.getToViewId();
+
             if ((cncFromAction != null) && (fromOutcome == null)) {
                 if (cncFromAction.equals(fromAction)) {
                     result.viewId = toViewId;
@@ -400,19 +400,13 @@
                     return result;
                 }
             }
- }
-
- for (int i = 0; i < caseList.size(); i++) {
- ConfigNavigationCase cnc = (ConfigNavigationCase)
caseList.get(i);
- cncFromAction = cnc.getFromAction();
- fromOutcome = cnc.getFromOutcome();
- toViewId = cnc.getToViewId();
+
             if ((cncFromAction == null) && (fromOutcome == null)) {
                 result.viewId = toViewId;
                 result.navCase = cnc;
                 return result;
             }
- }
+ }
 
         return null;
     }