Author: hlship
Date: Thu Sep  4 16:20:13 2008
New Revision: 692301

URL: http://svn.apache.org/viewvc?rev=692301&view=rev
Log:
TAPESTRY-2610: Allow access to component's informal parameters

Added:
    
tapestry/tapestry5/trunk/tapestry-core/src/test/app1/InformalParametersDemo.tml
    
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/components/ListInformals.java
    
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/InformalParametersDemo.java
Modified:
    
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/ComponentResources.java
    
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/structure/InternalComponentResourcesImpl.java
    
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/IntegrationTests.java
    
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/Start.java

Modified: 
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/ComponentResources.java
URL: 
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/ComponentResources.java?rev=692301&r1=692300&r2=692301&view=diff
==============================================================================
--- 
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/ComponentResources.java
 (original)
+++ 
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/ComponentResources.java
 Thu Sep  4 16:20:13 2008
@@ -22,6 +22,7 @@
 import org.apache.tapestry5.runtime.PageLifecycleListener;
 
 import java.lang.annotation.Annotation;
+import java.util.List;
 
 /**
  * Provides a component instance with the resources provided by the framework. 
In many circumstances, the resources
@@ -227,4 +228,22 @@
      * @return the element name or null
      */
     String getElementName();
+
+    /**
+     * Returns a list of the names of any informal parameters bound to this 
component.
+     *
+     * @return the name sorted alphabetically
+     * @see org.apache.tapestry5.annotations.SupportsInformalParameters
+     */
+    List<String> getInformalParameterNames();
+
+    /**
+     * Reads an informal parameter and [EMAIL PROTECTED] 
org.apache.tapestry5.ioc.services.TypeCoercer coercers) the bound
+     * value to the indicated type.
+     *
+     * @param name name of informal parameter
+     * @param type output value type
+     * @return instance of type
+     */
+    <T> T getInformalParameter(String name, Class<T> type);
 }

Modified: 
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/structure/InternalComponentResourcesImpl.java
URL: 
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/structure/InternalComponentResourcesImpl.java?rev=692301&r1=692300&r2=692301&view=diff
==============================================================================
--- 
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/structure/InternalComponentResourcesImpl.java
 (original)
+++ 
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/structure/InternalComponentResourcesImpl.java
 Thu Sep  4 16:20:13 2008
@@ -33,6 +33,7 @@
 import org.slf4j.Logger;
 
 import java.lang.annotation.Annotation;
+import java.util.List;
 import java.util.Locale;
 import java.util.Map;
 
@@ -154,6 +155,18 @@
         return getElementName(null);
     }
 
+    public List<String> getInformalParameterNames()
+    {
+        return InternalUtils.sortedKeys(getInformalParameterBindings());
+    }
+
+    public <T> T getInformalParameter(String name, Class<T> type)
+    {
+        if (getBinding(name) != null) return readParameter(name, type);
+
+        return null;
+    }
+
     public boolean hasBody()
     {
         return element.hasBody();
@@ -348,7 +361,7 @@
 
             if (value == null) continue;
 
-            // Because Blocks can be passed in (right from the template, using 
<t:parameter>,
+            // Because Blocks can be passed in (right from the template, using 
<t:parameter>),
             // we want to skip those when rending informal parameters.
 
             if (value instanceof Block) continue;
@@ -405,12 +418,7 @@
 
     public Block getBlockParameter(String parameterName)
     {
-        // Is allowed explicitly to not exist and be informal, otherwise the
-        // component in question would just use @Parameter.
-
-        if (getBinding(parameterName) != null) return 
readParameter(parameterName, Block.class);
-
-        return null;
+        return getInformalParameter(parameterName, Block.class);
     }
 
     public Block findBlock(String blockId)

Added: 
tapestry/tapestry5/trunk/tapestry-core/src/test/app1/InformalParametersDemo.tml
URL: 
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/app1/InformalParametersDemo.tml?rev=692301&view=auto
==============================================================================
--- 
tapestry/tapestry5/trunk/tapestry-core/src/test/app1/InformalParametersDemo.tml 
(added)
+++ 
tapestry/tapestry5/trunk/tapestry-core/src/test/app1/InformalParametersDemo.tml 
Thu Sep  4 16:20:13 2008
@@ -0,0 +1,6 @@
+<html t:type="Border" 
xmlns:t="http://tapestry.apache.org/schema/tapestry_5_0_0.xsd";>
+    <h1>Informal Parameters Demo</h1>
+
+    <t:listinformals fred="flintstone" barney="rubble" 
pageName="prop:componentResources.pageName"/>
+
+</html>
\ No newline at end of file

Modified: 
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/IntegrationTests.java
URL: 
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/IntegrationTests.java?rev=692301&r1=692300&r2=692301&view=diff
==============================================================================
--- 
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/IntegrationTests.java
 (original)
+++ 
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/IntegrationTests.java
 Thu Sep  4 16:20:13 2008
@@ -2226,4 +2226,15 @@
 
         waitForCondition(condition, PAGE_LOAD_TIMEOUT);
     }
+
+    /**
+     * TAPESTRY-2610
+     */
+    public void access_to_informal_parameters()
+    {
+        start("Informal Parameters Demo");
+
+        assertTextSeries("//[EMAIL PROTECTED]'informals']/dt[%d]", 1, 
"barney", "fred", "pageName");
+        assertTextSeries("//[EMAIL PROTECTED]'informals']/dd[%d]", 1, 
"rubble", "flintstone", "InformalParametersDemo");
+    }
 }

Added: 
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/components/ListInformals.java
URL: 
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/components/ListInformals.java?rev=692301&view=auto
==============================================================================
--- 
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/components/ListInformals.java
 (added)
+++ 
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/components/ListInformals.java
 Thu Sep  4 16:20:13 2008
@@ -0,0 +1,45 @@
+//  Copyright 2008 The Apache Software Foundation
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//     http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package org.apache.tapestry5.integration.app1.components;
+
+import org.apache.tapestry5.ComponentResources;
+import org.apache.tapestry5.MarkupWriter;
+import org.apache.tapestry5.annotations.SupportsInformalParameters;
+import org.apache.tapestry5.ioc.annotations.Inject;
+
[EMAIL PROTECTED]
+public class ListInformals
+{
+    @Inject
+    private ComponentResources resources;
+
+    void beginRender(MarkupWriter writer)
+    {
+        writer.element("dl", "id", "informals");
+
+        for (String name : resources.getInformalParameterNames())
+        {
+            writer.element("dt");
+            writer.write(name);
+            writer.end();
+
+            writer.element("dd");
+            writer.write(resources.getInformalParameter(name, String.class));
+            writer.end();
+        }
+
+        writer.end(); // dl
+    }
+}

Added: 
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/InformalParametersDemo.java
URL: 
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/InformalParametersDemo.java?rev=692301&view=auto
==============================================================================
--- 
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/InformalParametersDemo.java
 (added)
+++ 
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/InformalParametersDemo.java
 Thu Sep  4 16:20:13 2008
@@ -0,0 +1,19 @@
+//  Copyright 2008 The Apache Software Foundation
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//     http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package org.apache.tapestry5.integration.app1.pages;
+
+public class InformalParametersDemo
+{
+}

Modified: 
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/Start.java
URL: 
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/Start.java?rev=692301&r1=692300&r2=692301&view=diff
==============================================================================
--- 
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/Start.java
 (original)
+++ 
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/Start.java
 Thu Sep  4 16:20:13 2008
@@ -275,8 +275,12 @@
             new Item("methodadvicedemo", "Method Advice Demo", "Advising 
component methods."),
 
             new Item("HasBodyDemo", "Has Body Demo", "Verify the hasBody() 
method of ComponentResources"),
+
             new Item("BeanEditorBeanEditContext", "BeanEditor BeanEditContext",
-                     "BeanEditContext is pushed into enviroment by 
BeanEditor.")
+                     "BeanEditContext is pushed into enviroment by 
BeanEditor."),
+
+            new Item("InformalParametersDemo", "Informal Parameters Demo",
+                     "Access to informal parameters names and values")
     );
 
     static


Reply via email to