tapestry-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hls...@apache.org
Subject svn commit: r495804 - in /tapestry/tapestry5/tapestry-core/trunk/src: main/java/org/apache/tapestry/corelib/components/ main/java/org/apache/tapestry/internal/services/ test/app1/WEB-INF/ test/java/org/apache/tapestry/integration/ test/java/org/apache/...
Date Sat, 13 Jan 2007 00:43:32 GMT
Author: hlship
Date: Fri Jan 12 16:43:31 2007
New Revision: 495804

URL: http://svn.apache.org/viewvc?view=rev&rev=495804
Log:
Add support for the <t:parameter> element, to binding parameters of type Block.
Add an else parameter (type Block) to the If component.

Modified:
    tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/corelib/components/If.java
    tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/PageLoaderProcessor.java
    tapestry/tapestry5/tapestry-core/trunk/src/test/app1/WEB-INF/RenderComponentDemo.html
    tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/integration/IntegrationTests.java
    tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/integration/app1/pages/RenderComponentDemo.java

Modified: tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/corelib/components/If.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/corelib/components/If.java?view=diff&rev=495804&r1=495803&r2=495804
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/corelib/components/If.java
(original)
+++ tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/corelib/components/If.java
Fri Jan 12 16:43:31 2007
@@ -12,30 +12,41 @@
 // See the License for the specific language governing permissions and
 // limitations under the License.
 
-package org.apache.tapestry.corelib.components;
-
-import org.apache.tapestry.annotations.BeforeRenderBody;
-import org.apache.tapestry.annotations.ComponentClass;
-import org.apache.tapestry.annotations.Parameter;
-
-/**
- * Conditionally renders its body.
- * 
- * 
- */
-@ComponentClass
-public class If
-{
-    @Parameter(required = true)
-    private boolean _test;
-
-    /**
-     * If the test parameter is true, then the body is rendered, otherwise not. The component
does
-     * not have a template or do any other rendering besides its body.
-     */
-    @BeforeRenderBody
-    boolean renderBody()
-    {
-        return _test;
-    }
-}
+package org.apache.tapestry.corelib.components;
+
+import org.apache.tapestry.Block;
+import org.apache.tapestry.annotations.ComponentClass;
+import org.apache.tapestry.annotations.Parameter;
+
+/**
+ * Conditionally renders its body.
+ */
+@ComponentClass
+public class If
+{
+    @Parameter(required = true)
+    private boolean _test;
+
+    @Parameter
+    private Block _else;
+
+    /**
+     * Returns null if the test parameter is true, which allows normal rendering (of the
body). If
+     * the test parameter is false, returns the else parameter (this may also be null).
+     * 
+     * @return
+     */
+    Object beginRender()
+    {
+        return _test ? null : _else;
+    }
+
+    /**
+     * If the test parameter is true, then the body is rendered, otherwise not. The component
does
+     * not have a template or do any other rendering besides its body.
+     */
+    boolean beforeRenderBody()
+    {
+        return _test;
+    }
+}

Modified: tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/PageLoaderProcessor.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/PageLoaderProcessor.java?view=diff&rev=495804&r1=495803&r2=495804
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/PageLoaderProcessor.java
(original)
+++ tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/PageLoaderProcessor.java
Fri Jan 12 16:43:31 2007
@@ -26,6 +26,7 @@
 import org.apache.tapestry.Binding;
 import org.apache.tapestry.ComponentResources;
 import org.apache.tapestry.internal.InternalConstants;
+import org.apache.tapestry.internal.bindings.LiteralBinding;
 import org.apache.tapestry.internal.parser.AttributeToken;
 import org.apache.tapestry.internal.parser.BlockToken;
 import org.apache.tapestry.internal.parser.BodyToken;
@@ -33,6 +34,7 @@
 import org.apache.tapestry.internal.parser.ComponentTemplate;
 import org.apache.tapestry.internal.parser.EndElementToken;
 import org.apache.tapestry.internal.parser.ExpansionToken;
+import org.apache.tapestry.internal.parser.ParameterToken;
 import org.apache.tapestry.internal.parser.StartComponentToken;
 import org.apache.tapestry.internal.parser.StartElementToken;
 import org.apache.tapestry.internal.parser.TemplateToken;
@@ -403,6 +405,10 @@
                     block((BlockToken) token);
                     break;
 
+                case PARAMETER:
+                    parameter((ParameterToken) token);
+                    break;
+                    
                 default:
                     throw new IllegalStateException("Not implemented yet: " + token);
             }
@@ -416,19 +422,22 @@
         // as the ComponentTemplate is valid.
     }
 
-    private void block(BlockToken token)
+    private void parameter(ParameterToken token)
     {
-        // Don't use the page element factory here becauses we need something that is both
Block and
-        // BodyPageElement
-        // and don't want to use casts.
-
         BlockImpl block = new BlockImpl(token.getLocation());
+        String name = token.getName();
 
-        String id = token.getId();
+        Binding binding = new LiteralBinding("block parameter " + name, block, token.getLocation());
 
-        if (id != null)
-            _loadingElement.addBlock(id, block);
+        // TODO: Check that the t:parameter doesn't appear outside of an embedded component.
 
+        _activeElementStack.peek().addParameter(name, binding);
+
+        setupBlock(block);
+    }
+
+    private void setupBlock(BodyPageElement block)
+    {
         _bodyPageElementStack.addFirst(block);
         _discardEndTagStack.addFirst(true);
 
@@ -441,6 +450,22 @@
         };
 
         _endElementCommandStack.add(cleanup);
+    }
+
+    private void block(BlockToken token)
+    {
+        // Don't use the page element factory here becauses we need something that is both
Block and
+        // BodyPageElement
+        // and don't want to use casts.
+
+        BlockImpl block = new BlockImpl(token.getLocation());
+
+        String id = token.getId();
+
+        if (id != null)
+            _loadingElement.addBlock(id, block);
+
+        setupBlock(block);
     }
 
     private void startComponent(StartComponentToken token)

Modified: tapestry/tapestry5/tapestry-core/trunk/src/test/app1/WEB-INF/RenderComponentDemo.html
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/test/app1/WEB-INF/RenderComponentDemo.html?view=diff&rev=495804&r1=495803&r2=495804
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/test/app1/WEB-INF/RenderComponentDemo.html
(original)
+++ tapestry/tapestry5/tapestry-core/trunk/src/test/app1/WEB-INF/RenderComponentDemo.html
Fri Jan 12 16:43:31 2007
@@ -18,10 +18,11 @@
     
     <t:comp type="If" test="enabled">
         Should now show up:
+        <t:parameter name="else">
+            Should be blank:            
+        </t:parameter>
     </t:comp>
-    <t:comp type="If" test="disabled">
-        Should be blank:
-    </t:comp>
+
     <span id="container">[<t:comp type="Render" value="thing"/>]</span>
     
     

Modified: tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/integration/IntegrationTests.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/integration/IntegrationTests.java?view=diff&rev=495804&r1=495803&r2=495804
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/integration/IntegrationTests.java
(original)
+++ tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/integration/IntegrationTests.java
Fri Jan 12 16:43:31 2007
@@ -487,6 +487,10 @@
 
         assertText("//span[@id='container']", "[]");
 
+        // Sneak in a little test for If and parameter else:
+
+        assertTextPresent("Should be blank:");
+
         clickAndWait("enabled");
 
         // After clicking the link (which submits the form), the page re-renders and shows
us
@@ -494,6 +498,8 @@
         // after all.
 
         assertText("//span[@id='optional']", "Optional Text");
+
+        assertTextPresent("Should now show up:");
     }
 
     /**

Modified: tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/integration/app1/pages/RenderComponentDemo.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/integration/app1/pages/RenderComponentDemo.java?view=diff&rev=495804&r1=495803&r2=495804
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/integration/app1/pages/RenderComponentDemo.java
(original)
+++ tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/integration/app1/pages/RenderComponentDemo.java
Fri Jan 12 16:43:31 2007
@@ -38,11 +38,6 @@
         _enabled = enable;
     }
 
-    public boolean isDisabled()
-    {
-        return !_enabled;
-    }
-
     public Object getThing()
     {
         return _enabled ? _optional : null;



Mime
View raw message