You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tapestry.apache.org by th...@apache.org on 2019/09/21 14:28:07 UTC
[tapestry-5] branch master updated: TAP5-2615: If component now has
an optional 'then' block parameter
This is an automated email from the ASF dual-hosted git repository.
thiagohp pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/tapestry-5.git
The following commit(s) were added to refs/heads/master by this push:
new 7b1b5bb TAP5-2615: If component now has an optional 'then' block parameter
7b1b5bb is described below
commit 7b1b5bb4b1e5c5c2c6c1816e7b7f4d034008311f
Author: Thiago H. de Paula Figueiredo <th...@arsmachina.com.br>
AuthorDate: Sat Sep 21 11:27:57 2019 -0300
TAP5-2615: If component now has an optional 'then' block parameter
---
.../corelib/base/AbstractConditional.java | 9 +++++-
tapestry-core/src/test/app1/IfDemo.tml | 34 ++++++++++++++++++++++
.../tapestry5/integration/app1/pages/IfDemo.java | 20 +++++++++++++
.../tapestry5/integration/app1/pages/Index.java | 4 ++-
.../tapestry5/integration/pagelevel/IfTest.java | 4 +++
.../integration/app2/pages/TestPageForIf.tml | 16 ++++++++++
6 files changed, 85 insertions(+), 2 deletions(-)
diff --git a/tapestry-core/src/main/java/org/apache/tapestry5/corelib/base/AbstractConditional.java b/tapestry-core/src/main/java/org/apache/tapestry5/corelib/base/AbstractConditional.java
index 4402d1e..f098f33 100644
--- a/tapestry-core/src/main/java/org/apache/tapestry5/corelib/base/AbstractConditional.java
+++ b/tapestry-core/src/main/java/org/apache/tapestry5/corelib/base/AbstractConditional.java
@@ -44,6 +44,13 @@ public abstract class AbstractConditional
protected abstract boolean test();
/**
+ * The {@link org.apache.tapestry5.Block} to render if {@link #test()} is true. The default, null, means
+ * render the component body in that situation..
+ */
+ @Parameter(name = "then", defaultPrefix = BindingConstants.LITERAL)
+ private Block thenBlock;
+
+ /**
* An alternate {@link org.apache.tapestry5.Block} to render if {@link #test()} is false. The default, null, means
* render nothing in that situation.
*/
@@ -60,7 +67,7 @@ public abstract class AbstractConditional
{
boolean enabled = test();
- Block toRender = enabled ? resources.getBody() : elseBlock;
+ Block toRender = enabled ? (thenBlock == null ? resources.getBody() : thenBlock) : elseBlock;
String elementName = resources.getElementName();
diff --git a/tapestry-core/src/test/app1/IfDemo.tml b/tapestry-core/src/test/app1/IfDemo.tml
new file mode 100644
index 0000000..2240477
--- /dev/null
+++ b/tapestry-core/src/test/app1/IfDemo.tml
@@ -0,0 +1,34 @@
+<html t:type="Border" xmlns:t="http://tapestry.apache.org/schema/tapestry_5_0_0.xsd" xmlns:p="tapestry:parameter">
+
+ <p t:type="If" test="returntrue" id="originalIf">
+ original if
+ </p>
+
+ <p t:type="If" test="returntrue" id="originalIfElse">
+ original then
+ <p:else>
+ original else
+ </p:else>
+ </p>
+
+ <p t:type="If" test="returntrue" id="originalIfThenElse">
+ This appear in the output at all
+ <p:then>
+ new then
+ </p:then>
+ <p:else>
+ new else
+ </p:else>
+ </p>
+
+ <p t:type="If" test="!returntrue" id="else">
+ This shouldn't appear in the output at all
+ <p:then>
+ new then
+ </p:then>
+ <p:else>
+ just else
+ </p:else>
+ </p>
+
+</html>
\ No newline at end of file
diff --git a/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/IfDemo.java b/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/IfDemo.java
new file mode 100644
index 0000000..4781279
--- /dev/null
+++ b/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/IfDemo.java
@@ -0,0 +1,20 @@
+// 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 IfDemo
+{
+ public boolean getReturnTrue() {
+ return true;
+ }
+}
diff --git a/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/Index.java b/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/Index.java
index 2c87ae7..1b88561 100644
--- a/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/Index.java
+++ b/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/Index.java
@@ -615,7 +615,9 @@ public class Index
new Item("BeanEditorWithFormFragmentDemo", "Bean Editor With Form Fragment Demo", "TriggerFragment mixin used inside a BeanEditor"),
- new Item("ObjectEditorDemo","Object Editor Demo","Edit Bean with address objects")
+ new Item("ObjectEditorDemo","Object Editor Demo","Edit Bean with address objects"),
+
+ new Item("IfDemo","If Demo","If component with all its options")
);
static
diff --git a/tapestry-core/src/test/java/org/apache/tapestry5/integration/pagelevel/IfTest.java b/tapestry-core/src/test/java/org/apache/tapestry5/integration/pagelevel/IfTest.java
index d924b40..4ade164 100644
--- a/tapestry-core/src/test/java/org/apache/tapestry5/integration/pagelevel/IfTest.java
+++ b/tapestry-core/src/test/java/org/apache/tapestry5/integration/pagelevel/IfTest.java
@@ -35,10 +35,14 @@ public class IfTest extends Assert
assertNotNull(doc.getElementById("5"));
assertNotNull(doc.getElementById("8"));
assertNotNull(doc.getElementById("9"));
+ assertNotNull(doc.getElementById("10"));
+ assertNotNull(doc.getElementById("13"));
assertNull(doc.getElementById("2"));
assertNull(doc.getElementById("4"));
assertNull(doc.getElementById("6"));
assertNull(doc.getElementById("7"));
+ assertNull(doc.getElementById("11"));
+ assertNull(doc.getElementById("12"));
}
@AfterMethod
diff --git a/tapestry-core/src/test/resources/org/apache/tapestry5/integration/app2/pages/TestPageForIf.tml b/tapestry-core/src/test/resources/org/apache/tapestry5/integration/app2/pages/TestPageForIf.tml
index 48b985d..227f35c 100644
--- a/tapestry-core/src/test/resources/org/apache/tapestry5/integration/app2/pages/TestPageForIf.tml
+++ b/tapestry-core/src/test/resources/org/apache/tapestry5/integration/app2/pages/TestPageForIf.tml
@@ -29,4 +29,20 @@
<p id="9">foo</p>
</div>
</t:loop>
+ <t:if test="true">
+ <t:parameter name="then">
+ <p id="10">blah.</p>
+ </t:parameter>
+ <t:parameter name="else">
+ <p id="11">hey.</p>
+ </t:parameter>
+ </t:if>
+ <t:if test="false">
+ <t:parameter name="then">
+ <p id="12">blah.</p>
+ </t:parameter>
+ <t:parameter name="else">
+ <p id="13">hey.</p>
+ </t:parameter>
+ </t:if>
</html>