Author: hlship
Date: Sun Mar  2 13:54:29 2008
New Revision: 632855

URL: http://svn.apache.org/viewvc?rev=632855&view=rev
Log:
TAPESTRY-2221: Exception message when a context value is null or blank is 
confusing

Modified:
    
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/services/LinkFactoryImpl.java
    
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/services/ServicesMessages.java
    
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/services/TapestryModule.java
    
tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry/internal/services/ServicesStrings.properties
    tapestry/tapestry5/trunk/tapestry-core/src/test/app1/PageLinkContext.tml
    
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/integration/IntegrationTests.java
    
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/integration/app1/pages/PageLinkContext.java

Modified: 
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/services/LinkFactoryImpl.java
URL: 
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/services/LinkFactoryImpl.java?rev=632855&r1=632854&r2=632855&view=diff
==============================================================================
--- 
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/services/LinkFactoryImpl.java
 (original)
+++ 
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/services/LinkFactoryImpl.java
 Sun Mar  2 13:54:29 2008
@@ -24,6 +24,7 @@
 import static org.apache.tapestry.ioc.internal.util.CollectionFactory.*;
 import static org.apache.tapestry.ioc.internal.util.Defense.notBlank;
 import static org.apache.tapestry.ioc.internal.util.Defense.notNull;
+import org.apache.tapestry.ioc.internal.util.InternalUtils;
 import org.apache.tapestry.ioc.util.StrategyRegistry;
 import org.apache.tapestry.services.ContextValueEncoder;
 import org.apache.tapestry.services.Request;
@@ -252,8 +253,17 @@
 
         String[] result = new String[context.length];
 
-        for (int i = 0; i < context.length; i++)
-            result[i] = _contextValueEncoder.toClient(context[i]);
+        for (int i = 0; i < context.length; i++)    {
+
+            Object value = context[i];
+
+            String encoded = value == null ? null : 
_contextValueEncoder.toClient(value);
+
+            if (InternalUtils.isBlank(encoded))
+            throw new 
RuntimeException(ServicesMessages.contextValueMayNotBeNull());
+
+            result[i]= encoded;
+        }
 
         return result;
     }

Modified: 
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/services/ServicesMessages.java
URL: 
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/services/ServicesMessages.java?rev=632855&r1=632854&r2=632855&view=diff
==============================================================================
--- 
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/services/ServicesMessages.java
 (original)
+++ 
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/services/ServicesMessages.java
 Sun Mar  2 13:54:29 2008
@@ -405,4 +405,9 @@
     {
         return MESSAGES.format("no-such-method", 
ClassFabUtils.toJavaClassName(clazz), methodName);
     }
+
+    static String contextValueMayNotBeNull()
+    {
+        return MESSAGES.get("context-value-may-not-be-null");
+    }
 }

Modified: 
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/services/TapestryModule.java
URL: 
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/services/TapestryModule.java?rev=632855&r1=632854&r2=632855&view=diff
==============================================================================
--- 
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/services/TapestryModule.java
 (original)
+++ 
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/services/TapestryModule.java
 Sun Mar  2 13:54:29 2008
@@ -1181,10 +1181,10 @@
     /**
      * The MasterDispatcher is a chain-of-command of individual Dispatchers, 
each handling (like a servlet) a particular
      * kind of incoming request. <dl> <dt>RootPath</dt> <dd>Renders the start 
page for the "/" request</dd>
-     * <dt>Asset</dt> <dd>Provides access to classpath assets</dd> 
<dt>PageRender</dt> <dd>Identifies the page name and
-     * activation context and forwards onto [EMAIL PROTECTED] 
PageRenderRequestHandler}</dd> <dt>ComponentEvent</dt> <dd>Identifies
-     * the [EMAIL PROTECTED] ComponentEventRequestParameters} and forwards 
onto the [EMAIL PROTECTED] ComponentEventRequestHandler}</dd>
-     * </dl>
+     * <dt>Asset</dt> <dd>Provides access to classpath assets</dd> 
<dt>PageRender</dt> <dd>Identifies the [EMAIL PROTECTED]
+     * org.apache.tapestry.services.PageRenderRequestParameters} and forwards 
onto [EMAIL PROTECTED] PageRenderRequestHandler}</dd>
+     * <dt>ComponentEvent</dt> <dd>Identifies the [EMAIL PROTECTED] 
ComponentEventRequestParameters} and forwards onto the [EMAIL PROTECTED]
+     * ComponentEventRequestHandler}</dd> </dl>
      */
     public void contributeMasterDispatcher(OrderedConfiguration<Dispatcher> 
configuration,
 
@@ -1205,7 +1205,8 @@
                                            @Symbol("tapestry.start-page-name")
                                            String startPageName)
     {
-        // Looks for the root path and renders the start page
+        // Looks for the root path and renders the start page. This is 
maintained for compatibility
+        // with earlier versions of Tapestry 5, it is recommended that an 
Index page be used instead.
 
         configuration.add("RootPath",
                           new RootPathDispatcher(componentClassResolver, 
pageRenderRequestHandler, startPageName),
@@ -1214,15 +1215,16 @@
         // This goes first because an asset to be streamed may have an file 
extension, such as
         // ".html", that will confuse the later dispatchers.
 
-        configuration.add("Asset", new AssetDispatcher(streamer, aliasManager, 
resourceCache), "before:PageRender");
+        configuration.add("Asset", new AssetDispatcher(streamer, aliasManager, 
resourceCache), "before:ComponentEvent");
 
-        configuration.add("PageRender", new 
PageRenderDispatcher(componentClassResolver, pageRenderRequestHandler,
-                                                                 
contextValueEncoder));
 
         configuration.add("ComponentEvent",
                           new 
ComponentEventDispatcher(componentEventRequestHandler, componentClassResolver,
                                                        contextValueEncoder),
                           "before:PageRender");
+
+        configuration.add("PageRender", new 
PageRenderDispatcher(componentClassResolver, pageRenderRequestHandler,
+                                                                 
contextValueEncoder));
     }
 
     /**

Modified: 
tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry/internal/services/ServicesStrings.properties
URL: 
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry/internal/services/ServicesStrings.properties?rev=632855&r1=632854&r2=632855&view=diff
==============================================================================
--- 
tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry/internal/services/ServicesStrings.properties
 (original)
+++ 
tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry/internal/services/ServicesStrings.properties
 Sun Mar  2 13:54:29 2008
@@ -92,3 +92,4 @@
 no-translator-for-type=No translator is defined for type %s.  Registered 
types: %s.
 parameter-binding-must-not-be-empty=Parameter '%s' must have a non-empty 
binding.
 no-such-method=Class %s does not contain a method named '%s()'.
+context-value-may-not-be-null=Context values (which are added to the request 
URL) may not be null or blank.

Modified: 
tapestry/tapestry5/trunk/tapestry-core/src/test/app1/PageLinkContext.tml
URL: 
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/app1/PageLinkContext.tml?rev=632855&r1=632854&r2=632855&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/test/app1/PageLinkContext.tml 
(original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/test/app1/PageLinkContext.tml 
Sun Mar  2 13:54:29 2008
@@ -17,6 +17,8 @@
     <a t:type="pagelink" page="target" context="unsafeCharacters">unsafe 
characters</a>
     <br/>
     <a t:type="pagelink" page="target" context="japaneseKanji">japanese 
kanji</a>
+    <br/>
+    <t:actionlink t:id="nullContext">Null in ontext</t:actionlink>
 
 
 </html>

Modified: 
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/integration/IntegrationTests.java
URL: 
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/integration/IntegrationTests.java?rev=632855&r1=632854&r2=632855&view=diff
==============================================================================
--- 
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/integration/IntegrationTests.java
 (original)
+++ 
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/integration/IntegrationTests.java
 Sun Mar  2 13:54:29 2008
@@ -772,6 +772,14 @@
         clickAndWait("link=japanese kanji");
 
         assertText("//li[1]", "japanese kanji: \u65E5\u672C\u8A9E");
+
+        // TAPESTRY-2221
+
+        clickAndWait("link=PageLink Context Demo");
+
+        clickAndWait("link=Null in context");
+
+        assertTextPresent("Context values (which are added to the request URL) 
may not be null or blank.");
     }
 
     @Test

Modified: 
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/integration/app1/pages/PageLinkContext.java
URL: 
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/integration/app1/pages/PageLinkContext.java?rev=632855&r1=632854&r2=632855&view=diff
==============================================================================
--- 
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/integration/app1/pages/PageLinkContext.java
 (original)
+++ 
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/integration/app1/pages/PageLinkContext.java
 Sun Mar  2 13:54:29 2008
@@ -14,11 +14,17 @@
 
 package org.apache.tapestry.integration.app1.pages;
 
+import org.apache.tapestry.ComponentResources;
+import org.apache.tapestry.ioc.annotations.Inject;
+
 public class PageLinkContext
 {
+    @Inject
+    private ComponentResources _resources;
+
     public Object[] getComputedContext()
     {
-        return new Object[]{"fred", 7, true};
+        return new Object[] { "fred", 7, true };
     }
 
     public String getUnsafeCharacters()
@@ -30,4 +36,10 @@
     {
         return "japanese kanji: \u65E5\u672C\u8A9E";
     }
+
+    Object onActionFromNullContext()
+    {
+        return _resources.createPageLink("target", true, new Object[] { null 
});
+    }
+
 }


Reply via email to