myfaces-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jak...@apache.org
Subject svn commit: r935728 - /myfaces/shared/trunk_4.0.x/core/src/main/java/org/apache/myfaces/shared/renderkit/html/HtmlRendererUtils.java
Date Mon, 19 Apr 2010 20:15:27 GMT
Author: jakobk
Date: Mon Apr 19 20:15:26 2010
New Revision: 935728

URL: http://svn.apache.org/viewvc?rev=935728&view=rev
Log:
MYFACES-2663 NPE in UIParameter when value resolves to null (skip UIParameter with null-value,
add an error message for UIParameter with a null-name when in Development stage, code cleanup
on getOutcomeTargetLinkHref())

Modified:
    myfaces/shared/trunk_4.0.x/core/src/main/java/org/apache/myfaces/shared/renderkit/html/HtmlRendererUtils.java

Modified: myfaces/shared/trunk_4.0.x/core/src/main/java/org/apache/myfaces/shared/renderkit/html/HtmlRendererUtils.java
URL: http://svn.apache.org/viewvc/myfaces/shared/trunk_4.0.x/core/src/main/java/org/apache/myfaces/shared/renderkit/html/HtmlRendererUtils.java?rev=935728&r1=935727&r2=935728&view=diff
==============================================================================
--- myfaces/shared/trunk_4.0.x/core/src/main/java/org/apache/myfaces/shared/renderkit/html/HtmlRendererUtils.java
(original)
+++ myfaces/shared/trunk_4.0.x/core/src/main/java/org/apache/myfaces/shared/renderkit/html/HtmlRendererUtils.java
Mon Apr 19 20:15:26 2010
@@ -35,9 +35,9 @@ import javax.faces.FacesException;
 import javax.faces.application.ConfigurableNavigationHandler;
 import javax.faces.application.NavigationCase;
 import javax.faces.application.NavigationHandler;
+import javax.faces.application.ProjectStage;
 import javax.faces.application.ViewHandler;
 import javax.faces.component.EditableValueHolder;
-import javax.faces.component.NamingContainer;
 import javax.faces.component.UIComponent;
 import javax.faces.component.UIInput;
 import javax.faces.component.UINamingContainer;
@@ -1820,34 +1820,29 @@ public final class HtmlRendererUtils {
     public static String getOutcomeTargetLinkHref (
             FacesContext facesContext, UIOutcomeTarget component) throws IOException
     {
-        String fragment = (String) component.getAttributes().get ("fragment");
-        String href = component.getOutcome();
-        ViewHandler viewHandler = facesContext.getApplication().getViewHandler();
-        
-        // The href for an HtmlOutcomeTargetLink is outcome#fragment.
-        
-        href = ((href == null) ? STR_EMPTY : href.trim());
+        String outcome = component.getOutcome();
+        outcome = ((outcome == null) ? STR_EMPTY : outcome.trim());
         
         // Get the correct URL for the outcome.
-        
         NavigationHandler nh = facesContext.getApplication().getNavigationHandler();
         if (!(nh instanceof ConfigurableNavigationHandler))
         {
-            throw new FacesException("navigation handler must be instance of ConfigurabeNavigationHandler
for use h:link or h:button");
+            throw new FacesException("Navigation handler must be an instance of " +
+                    "ConfigurableNavigationHandler for using h:link or h:button");
         }
         ConfigurableNavigationHandler navigationHandler = (ConfigurableNavigationHandler)
nh;
+        // fromAction is null because there is no action method that was called to get the
outcome
+        NavigationCase navigationCase = navigationHandler.getNavigationCase(facesContext,
null, outcome);
         
-        //fromAction is null because there
-        NavigationCase navigationCase = navigationHandler.getNavigationCase(facesContext,
null, href);
-
         // when navigation case is null, force the "link" to be rendered as text
         if (navigationCase == null)
         {
             return null;
         }
+        String href = navigationCase.getToViewId(facesContext);
         
-        href = navigationCase.getToViewId(facesContext);
-                
+        // handle fragment (viewId#fragment)
+        String fragment = (String) component.getAttributes().get ("fragment");
         if (fragment != null)
         {
             fragment = fragment.trim();
@@ -1858,34 +1853,50 @@ public final class HtmlRendererUtils {
             }
         }
         
+        // handle URL parameters
         Map<String, List<String>> parameters = new HashMap<String,List<String>>();
-        
-        for (Iterator it = component.getChildren().iterator(); it.hasNext(); )
+        for (Iterator<UIComponent> it = component.getChildren().iterator(); it.hasNext();
)
         {
-            UIComponent child = (UIComponent)it.next();
+            UIComponent child = (UIComponent) it.next();
             if (child instanceof UIParameter)
             {
+                UIParameter param = (UIParameter) child;
+                
                 // check for the disable attribute (since 2.0)
-                if (((UIParameter) child).isDisable())
+                if (param.isDisable())
                 {
                     // ignore this UIParameter and continue
                     continue;
                 }
-                String name = ((UIParameter)child).getName();
-                Object value = ((UIParameter)child).getValue();
+                String name = param.getName();
+                if ((name == null || STR_EMPTY.equals(name)) 
+                        && facesContext.isProjectStage(ProjectStage.Development))
+                {
+                    // warn for a null-name
+                    log.log(Level.WARNING, "The UIParameter " + RendererUtils.getPathToComponent(param)
+
+                            " has a name of null or empty string and thus will not be added
to the URL.");
+                    continue;
+                }
+                Object value = param.getValue();
+                if (value == null)
+                {
+                    // skip a null-value
+                    continue;
+                }
                 if (parameters.containsKey(name))
                 {
                     parameters.get(name).add(value.toString());
                 }
                 else
                 {
-                    ArrayList<String> list = new ArrayList<String>(1);
+                    List<String> list = new ArrayList<String>(1);
                     list.add(value.toString());
                     parameters.put(name, list);
                 }
             }
         }
         
+        // handle NavigationCase parameters
         if (navigationCase.isIncludeViewParams()) {
             parameters.putAll (navigationCase.getParameters());
         }
@@ -1893,7 +1904,9 @@ public final class HtmlRendererUtils {
         // In theory the precedence order to deal with params is this:
         // component parameters, navigation-case parameters, view parameters
         // getBookmarkableURL deal with this details.
-        href = viewHandler.getBookmarkableURL(facesContext, href, parameters, navigationCase.isIncludeViewParams()
|| component.isIncludeViewParams());
+        ViewHandler viewHandler = facesContext.getApplication().getViewHandler();
+        href = viewHandler.getBookmarkableURL(facesContext, href, parameters, 
+                navigationCase.isIncludeViewParams() || component.isIncludeViewParams());
                 
         return href;
     }



Mime
View raw message