Updated Branches: refs/heads/wicket-1.5.x a354b86af -> 88961c1a9
WICKET-5085 make id of enclosure stable in markup so that InlineEnclosure is resolved once only Project: http://git-wip-us.apache.org/repos/asf/wicket/repo Commit: http://git-wip-us.apache.org/repos/asf/wicket/commit/88961c1a Tree: http://git-wip-us.apache.org/repos/asf/wicket/tree/88961c1a Diff: http://git-wip-us.apache.org/repos/asf/wicket/diff/88961c1a Branch: refs/heads/wicket-1.5.x Commit: 88961c1a987be9a54be238b03457a7e2d5bfe37b Parents: a354b86 Author: svenmeier <[email protected]> Authored: Fri Mar 8 14:04:59 2013 +0100 Committer: svenmeier <[email protected]> Committed: Fri Mar 8 14:04:59 2013 +0100 ---------------------------------------------------------------------- .../markup/html/internal/InlineEnclosure.java | 34 --- .../parser/filter/InlineEnclosureHandler.java | 11 +- .../markup/html/internal/AjaxEnclosureTest.java | 10 +- .../InlineEnclosurePageExpectedResult_1.html | 96 ++++---- .../InlineEnclosurePageExpectedResult_2.html | 212 +++++++------- .../InlineEnclosurePanelPageExpectedResult.html | 36 ++-- .../markup/html/internal/InlineEnclosureTest.java | 40 +++- ...reWithWicketMessagePage_invisible_expected.html | 2 +- ...sureWithWicketMessagePage_visible_expected.html | 2 +- .../markup/html/internal/TogglePageTest.java | 4 +- 10 files changed, 223 insertions(+), 224 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/wicket/blob/88961c1a/wicket-core/src/main/java/org/apache/wicket/markup/html/internal/InlineEnclosure.java ---------------------------------------------------------------------- diff --git a/wicket-core/src/main/java/org/apache/wicket/markup/html/internal/InlineEnclosure.java b/wicket-core/src/main/java/org/apache/wicket/markup/html/internal/InlineEnclosure.java index f62604e..c63bb96 100644 --- a/wicket-core/src/main/java/org/apache/wicket/markup/html/internal/InlineEnclosure.java +++ b/wicket-core/src/main/java/org/apache/wicket/markup/html/internal/InlineEnclosure.java @@ -17,8 +17,6 @@ package org.apache.wicket.markup.html.internal; import org.apache.wicket.markup.ComponentTag; -import org.apache.wicket.markup.IMarkupFragment; -import org.apache.wicket.markup.Markup; import org.apache.wicket.markup.parser.filter.InlineEnclosureHandler; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -43,8 +41,6 @@ public class InlineEnclosure extends Enclosure private static final Logger log = LoggerFactory.getLogger(InlineEnclosure.class); - private String enclosureMarkupAsString; - /** * Construct. * @@ -55,8 +51,6 @@ public class InlineEnclosure extends Enclosure { super(id, childId); - enclosureMarkupAsString = null; - // ensure that the Enclosure is ready for ajax updates setOutputMarkupPlaceholderTag(true); setMarkupId(getId()); @@ -82,32 +76,4 @@ public class InlineEnclosure extends Enclosure setVisible(visible); return visible; } - - /** - * {@link InlineEnclosure}s keep their own cache of their markup because Component#markup is - * detached and later during Ajax request it is hard to re-lookup {@link InlineEnclosure}'s - * markup from its parent. - * - * @see org.apache.wicket.Component#getMarkup() - */ - @Override - public IMarkupFragment getMarkup() - { - IMarkupFragment enclosureMarkup = null; - if (enclosureMarkupAsString == null) - { - IMarkupFragment markup = super.getMarkup(); - if (markup != null && markup != Markup.NO_MARKUP) - { - enclosureMarkup = markup; - enclosureMarkupAsString = markup.toString(true); - } - } - else - { - enclosureMarkup = Markup.of(enclosureMarkupAsString); - } - - return enclosureMarkup; - } } http://git-wip-us.apache.org/repos/asf/wicket/blob/88961c1a/wicket-core/src/main/java/org/apache/wicket/markup/parser/filter/InlineEnclosureHandler.java ---------------------------------------------------------------------- diff --git a/wicket-core/src/main/java/org/apache/wicket/markup/parser/filter/InlineEnclosureHandler.java b/wicket-core/src/main/java/org/apache/wicket/markup/parser/filter/InlineEnclosureHandler.java index e661ea2..9166822 100644 --- a/wicket-core/src/main/java/org/apache/wicket/markup/parser/filter/InlineEnclosureHandler.java +++ b/wicket-core/src/main/java/org/apache/wicket/markup/parser/filter/InlineEnclosureHandler.java @@ -64,6 +64,12 @@ public final class InlineEnclosureHandler extends AbstractMarkupFilter private Stack<ComponentTag> enclosures; /** + * InlinceEnclosures are not removed after render as other auto-components, thus they have to + * have a stable id. + */ + private int counter; + + /** * Construct. */ public InlineEnclosureHandler() @@ -100,7 +106,8 @@ public final class InlineEnclosureHandler extends AbstractMarkupFilter { if (Strings.isEmpty(htmlId)) { - tag.setId(INLINE_ENCLOSURE_ID_PREFIX); + String id = INLINE_ENCLOSURE_ID_PREFIX + (counter++); + tag.setId(id); } else { @@ -175,7 +182,7 @@ public final class InlineEnclosureHandler extends AbstractMarkupFilter String inlineEnclosureChildId = getInlineEnclosureAttribute(tag); if (Strings.isEmpty(inlineEnclosureChildId) == false) { - String id = tag.getId() + container.getPage().getAutoIndex(); + String id = tag.getId(); // Yes, we handled the tag return new InlineEnclosure(id, inlineEnclosureChildId); } http://git-wip-us.apache.org/repos/asf/wicket/blob/88961c1a/wicket-core/src/test/java/org/apache/wicket/markup/html/internal/AjaxEnclosureTest.java ---------------------------------------------------------------------- diff --git a/wicket-core/src/test/java/org/apache/wicket/markup/html/internal/AjaxEnclosureTest.java b/wicket-core/src/test/java/org/apache/wicket/markup/html/internal/AjaxEnclosureTest.java index 571457f..7093d6d 100644 --- a/wicket-core/src/test/java/org/apache/wicket/markup/html/internal/AjaxEnclosureTest.java +++ b/wicket-core/src/test/java/org/apache/wicket/markup/html/internal/AjaxEnclosureTest.java @@ -34,9 +34,9 @@ public class AjaxEnclosureTest extends WicketTestCase { private final String inlineEnclosureIdPrefix = "InlineEnclosure-"; private final String inlineEnclosureHiddenPattern = "<div id=\"" + inlineEnclosureIdPrefix + - "1\" style=\"display:none\"></div>"; + "0\" style=\"display:none\"></div>"; private final String inlineEnclosureVisiblePattern = "<div id=\"" + inlineEnclosureIdPrefix + - "1\">"; + "0\">"; /** @@ -88,7 +88,7 @@ public class AjaxEnclosureTest extends WicketTestCase @Test public void ajaxTogglingNonControllingChildShouldNotToggleEnclosure() { - final String enclosurePath = "InlineEnclosure-1"; + final String enclosurePath = "InlineEnclosure-0"; { // label 2 On AjaxEnclosurePage_1 ajaxPage = tester.startPage(AjaxEnclosurePage_1.class); @@ -129,7 +129,7 @@ public class AjaxEnclosureTest extends WicketTestCase @Test public void nestedInlineEnclosuresShouldToggleNormally() { - final String enclosure1Path = "InlineEnclosure-1"; + final String enclosure1Path = "InlineEnclosure-0"; { // 1. test that enclosure1, enclosure2, label1, label2 are visible, click link1, @@ -219,7 +219,7 @@ public class AjaxEnclosureTest extends WicketTestCase @Test public void controllingChildShouldDefaultToTheSingleComponentInsideEnclosure() { - final String enclosurePath = "InlineEnclosure-1"; + final String enclosurePath = "InlineEnclosure-0"; { // enclosure On http://git-wip-us.apache.org/repos/asf/wicket/blob/88961c1a/wicket-core/src/test/java/org/apache/wicket/markup/html/internal/InlineEnclosurePageExpectedResult_1.html ---------------------------------------------------------------------- diff --git a/wicket-core/src/test/java/org/apache/wicket/markup/html/internal/InlineEnclosurePageExpectedResult_1.html b/wicket-core/src/test/java/org/apache/wicket/markup/html/internal/InlineEnclosurePageExpectedResult_1.html index 5b62b10..f24385e 100644 --- a/wicket-core/src/test/java/org/apache/wicket/markup/html/internal/InlineEnclosurePageExpectedResult_1.html +++ b/wicket-core/src/test/java/org/apache/wicket/markup/html/internal/InlineEnclosurePageExpectedResult_1.html @@ -1,48 +1,48 @@ -<html> -<body> - -<span id="InlineEnclosure-1"> <span>Test Label 1</span> </span> - -<div id="InlineEnclosure-2"> - <table> - <tr> - <td><span>Test Label 2</span></td> - </tr> - </table> -</div> - -<span id="InlineEnclosure-3" style="display:none"></span> - -<div id="InlineEnclosure-4"> - <table> - <tr> - <td><span>Test Label 4</span></td> - </tr> - </table> - <table> - <tr> - <td><span>Test Label 5</span></td> - </tr> - </table> - <table> - <tr> - <td><span>Test Label 6</span></td> - </tr> - </table> - <table> - <tr> - <td><span>Test Label 7</span></td> - </tr> - </table> -</div> - -<div id="InlineEnclosure-5"><span> <span>Test Label 8</span> </span></div> - -<div id="InlineEnclosure-6"><span>Test Label 9</span></div> - -<div id="customInlineEnclosureId7"><span>Test Label 10</span> -</div> - - -</body> -</html> +<html> +<body> + +<span id="InlineEnclosure-0"> <span>Test Label 1</span> </span> + +<div id="InlineEnclosure-1"> + <table> + <tr> + <td><span>Test Label 2</span></td> + </tr> + </table> +</div> + +<span id="InlineEnclosure-2" style="display:none"></span> + +<div id="InlineEnclosure-3"> + <table> + <tr> + <td><span>Test Label 4</span></td> + </tr> + </table> + <table> + <tr> + <td><span>Test Label 5</span></td> + </tr> + </table> + <table> + <tr> + <td><span>Test Label 6</span></td> + </tr> + </table> + <table> + <tr> + <td><span>Test Label 7</span></td> + </tr> + </table> +</div> + +<div id="InlineEnclosure-4"><span> <span>Test Label 8</span> </span></div> + +<div id="InlineEnclosure-5"><span>Test Label 9</span></div> + +<div id="customInlineEnclosureId"><span>Test Label 10</span> +</div> + + +</body> +</html> http://git-wip-us.apache.org/repos/asf/wicket/blob/88961c1a/wicket-core/src/test/java/org/apache/wicket/markup/html/internal/InlineEnclosurePageExpectedResult_2.html ---------------------------------------------------------------------- diff --git a/wicket-core/src/test/java/org/apache/wicket/markup/html/internal/InlineEnclosurePageExpectedResult_2.html b/wicket-core/src/test/java/org/apache/wicket/markup/html/internal/InlineEnclosurePageExpectedResult_2.html index c13c05e..ecb6125 100644 --- a/wicket-core/src/test/java/org/apache/wicket/markup/html/internal/InlineEnclosurePageExpectedResult_2.html +++ b/wicket-core/src/test/java/org/apache/wicket/markup/html/internal/InlineEnclosurePageExpectedResult_2.html @@ -1,106 +1,106 @@ -<html> -<body> - -<!-- nested inline enclosures with separate child depths. --> -<div id="InlineEnclosure-1"><span>Test Label 1</span> - <div id="InlineEnclosure-2"> - <table> - <tr> - <td><span>Test Label 2</span></td> - </tr> - </table> - </div> -</div> - -<!-- nested inline enclosures with same child depth. --> -<div id="InlineEnclosure-3"> - <div id="InlineEnclosure-4"> - <span>Test Label 3</span> - <span>Test Label 4</span> - </div> -</div> - -<!-- enclosure tag nested inside inline enclosure with separate child depths. --> -<div id="InlineEnclosure-5"> <span>Test Label 5</span> - - <table> - <tr> - <td> - <span>Test Label 6</span> - </td> - </tr> - </table> - -</div> - -<!-- enclosure tag nested inside inline enclosure with same child depth. --> -<div id="InlineEnclosure-7"> - - <table> - <tr> - <td> - <span>Test Label 7</span> - <span>Test Label 8</span> - </td> - </tr> - </table> - -</div> - -<!-- inline enclosure nested inside enclosure tag with separate child depths. --> - - <div id="InlineEnclosure-10"> <span>Test Label 9</span> - <table> - <tr> - <td><span>Test Label 10</span></td> - </tr> - </table> - </div> - - -<!-- inline enclosure nested inside enclosure tag with same child depth. --> -<div id="InlineEnclosure-11"> - - <table> - <tr> - <td> - <span>Test Label 11</span> - <span>Test Label 12</span> - </td> - </tr> - </table> - -</div> - -<!-- inline enclosure nested inside enclosure tag with same child depth inside a wicket container. --> - - <div id="InlineEnclosure-14"> - <div> - <table> - <tr> - <td> - <span>Test Label 13</span> - <span>Test Label 14</span> - </td> - </tr> - </table> - </div> - </div> - - - -<!-- nested inline enclosures without explicitly determining children --> -<div id="InlineEnclosure-15"> - <div id="InlineEnclosure-16"> - <table> - <tr> - <td> - <span>Test Label 15</span> - </td> - </tr> - </table> - </div> -</div> - -</body> -</html> +<html> +<body> + +<!-- nested inline enclosures with separate child depths. --> +<div id="InlineEnclosure-0"><span>Test Label 1</span> + <div id="InlineEnclosure-1"> + <table> + <tr> + <td><span>Test Label 2</span></td> + </tr> + </table> + </div> +</div> + +<!-- nested inline enclosures with same child depth. --> +<div id="InlineEnclosure-2"> + <div id="InlineEnclosure-3"> + <span>Test Label 3</span> + <span>Test Label 4</span> + </div> +</div> + +<!-- enclosure tag nested inside inline enclosure with separate child depths. --> +<div id="InlineEnclosure-4"> <span>Test Label 5</span> + + <table> + <tr> + <td> + <span>Test Label 6</span> + </td> + </tr> + </table> + +</div> + +<!-- enclosure tag nested inside inline enclosure with same child depth. --> +<div id="InlineEnclosure-5"> + + <table> + <tr> + <td> + <span>Test Label 7</span> + <span>Test Label 8</span> + </td> + </tr> + </table> + +</div> + +<!-- inline enclosure nested inside enclosure tag with separate child depths. --> + + <div id="InlineEnclosure-6"> <span>Test Label 9</span> + <table> + <tr> + <td><span>Test Label 10</span></td> + </tr> + </table> + </div> + + +<!-- inline enclosure nested inside enclosure tag with same child depth. --> +<div id="InlineEnclosure-7"> + + <table> + <tr> + <td> + <span>Test Label 11</span> + <span>Test Label 12</span> + </td> + </tr> + </table> + +</div> + +<!-- inline enclosure nested inside enclosure tag with same child depth inside a wicket container. --> + + <div id="InlineEnclosure-8"> + <div> + <table> + <tr> + <td> + <span>Test Label 13</span> + <span>Test Label 14</span> + </td> + </tr> + </table> + </div> + </div> + + + +<!-- nested inline enclosures without explicitly determining children --> +<div id="InlineEnclosure-9"> + <div id="InlineEnclosure-10"> + <table> + <tr> + <td> + <span>Test Label 15</span> + </td> + </tr> + </table> + </div> +</div> + +</body> +</html> http://git-wip-us.apache.org/repos/asf/wicket/blob/88961c1a/wicket-core/src/test/java/org/apache/wicket/markup/html/internal/InlineEnclosurePanelPageExpectedResult.html ---------------------------------------------------------------------- diff --git a/wicket-core/src/test/java/org/apache/wicket/markup/html/internal/InlineEnclosurePanelPageExpectedResult.html b/wicket-core/src/test/java/org/apache/wicket/markup/html/internal/InlineEnclosurePanelPageExpectedResult.html index 9f900eb..e1f3a5f 100644 --- a/wicket-core/src/test/java/org/apache/wicket/markup/html/internal/InlineEnclosurePanelPageExpectedResult.html +++ b/wicket-core/src/test/java/org/apache/wicket/markup/html/internal/InlineEnclosurePanelPageExpectedResult.html @@ -1,18 +1,18 @@ -<html> -<body> - <div id="InlineEnclosure-1"> - <div> - <div> - This is a simple test panel. This contains a label and an inline enclosure - with a label inside it. - <span>Inside InlineEnclosure and Panel: hello world</span> - - <div id="InlineEnclosure-2"> - <span>Inside InlineEnclosure, Panel and another InlineEnclosure: hello again.</span> - </div> - -</div> - </div> - </div> -</body> -</html> +<html> +<body> + <div id="InlineEnclosure-0"> + <div> + <div> + This is a simple test panel. This contains a label and an inline enclosure + with a label inside it. + <span>Inside InlineEnclosure and Panel: hello world</span> + + <div id="InlineEnclosure-0"> + <span>Inside InlineEnclosure, Panel and another InlineEnclosure: hello again.</span> + </div> + +</div> + </div> + </div> +</body> +</html> http://git-wip-us.apache.org/repos/asf/wicket/blob/88961c1a/wicket-core/src/test/java/org/apache/wicket/markup/html/internal/InlineEnclosureTest.java ---------------------------------------------------------------------- diff --git a/wicket-core/src/test/java/org/apache/wicket/markup/html/internal/InlineEnclosureTest.java b/wicket-core/src/test/java/org/apache/wicket/markup/html/internal/InlineEnclosureTest.java index f085672..399b9df 100644 --- a/wicket-core/src/test/java/org/apache/wicket/markup/html/internal/InlineEnclosureTest.java +++ b/wicket-core/src/test/java/org/apache/wicket/markup/html/internal/InlineEnclosureTest.java @@ -18,18 +18,44 @@ package org.apache.wicket.markup.html.internal; import org.apache.wicket.Page; import org.apache.wicket.WicketTestCase; +import org.apache.wicket.markup.parser.filter.InlineEnclosureHandler; import org.apache.wicket.protocol.http.WebApplication; import org.junit.Test; /** - * Simple test using the WicketTester + * Test for {@link InlineEnclosure} and {@link InlineEnclosureHandler}. * * @author Joonas Hamalainen */ public class InlineEnclosureTest extends WicketTestCase { /** + * WICKET-5085: Since {@link InlineEnclosure}s are not removed as other auto-Components, they + * must be resolved once only. + * + * @throws Exception + */ + @Test + public void inlineEnclosuresAreResolvedOnceOnly() throws Exception + { + InlineEnclosurePanelPage page = new InlineEnclosurePanelPage(); + + tester.startPage(page); + + assertEquals(2, page.visitChildren(InlineEnclosure.class).toList().size()); + + tester.startPage(page); + + assertEquals(2, page.visitChildren(InlineEnclosure.class).toList().size()); + + tester.startPage(page); + + assertEquals(2, page.visitChildren(InlineEnclosure.class).toList().size()); + } + + + /** * @throws Exception */ @Test @@ -58,22 +84,22 @@ public class InlineEnclosureTest extends WicketTestCase /** * https://issues.apache.org/jira/browse/WICKET-4520 - * + * * Tests that wicket:enclosure and wicket:message attributes can co-exist - * + * * @throws Exception */ @Test public void inlineEnclosureWithWicketMessageVisible() throws Exception { executeTest(new InlineEnclosureWithWicketMessagePage(true), - "InlineEnclosureWithWicketMessagePage_visible_expected.html"); + "InlineEnclosureWithWicketMessagePage_visible_expected.html"); } /** - * + * * https://issues.apache.org/jira/browse/WICKET-4520 - * + * * Tests that wicket:enclosure and wicket:message attributes can co-exist * * @throws Exception @@ -82,7 +108,7 @@ public class InlineEnclosureTest extends WicketTestCase public void inlineEnclosureWithWicketMessageInvisible() throws Exception { executeTest(new InlineEnclosureWithWicketMessagePage(false), - "InlineEnclosureWithWicketMessagePage_invisible_expected.html"); + "InlineEnclosureWithWicketMessagePage_invisible_expected.html"); } @Override http://git-wip-us.apache.org/repos/asf/wicket/blob/88961c1a/wicket-core/src/test/java/org/apache/wicket/markup/html/internal/InlineEnclosureWithWicketMessagePage_invisible_expected.html ---------------------------------------------------------------------- diff --git a/wicket-core/src/test/java/org/apache/wicket/markup/html/internal/InlineEnclosureWithWicketMessagePage_invisible_expected.html b/wicket-core/src/test/java/org/apache/wicket/markup/html/internal/InlineEnclosureWithWicketMessagePage_invisible_expected.html index 8ea5093..6252a42 100644 --- a/wicket-core/src/test/java/org/apache/wicket/markup/html/internal/InlineEnclosureWithWicketMessagePage_invisible_expected.html +++ b/wicket-core/src/test/java/org/apache/wicket/markup/html/internal/InlineEnclosureWithWicketMessagePage_invisible_expected.html @@ -21,6 +21,6 @@ <title>Wicket 4520</title> </head> <body> - <div id="_message_attr_1" style="display:none"></div> + <div id="_message_attr_" style="display:none"></div> </body> </html> \ No newline at end of file http://git-wip-us.apache.org/repos/asf/wicket/blob/88961c1a/wicket-core/src/test/java/org/apache/wicket/markup/html/internal/InlineEnclosureWithWicketMessagePage_visible_expected.html ---------------------------------------------------------------------- diff --git a/wicket-core/src/test/java/org/apache/wicket/markup/html/internal/InlineEnclosureWithWicketMessagePage_visible_expected.html b/wicket-core/src/test/java/org/apache/wicket/markup/html/internal/InlineEnclosureWithWicketMessagePage_visible_expected.html index d0bc411..62d9d09 100644 --- a/wicket-core/src/test/java/org/apache/wicket/markup/html/internal/InlineEnclosureWithWicketMessagePage_visible_expected.html +++ b/wicket-core/src/test/java/org/apache/wicket/markup/html/internal/InlineEnclosureWithWicketMessagePage_visible_expected.html @@ -21,7 +21,7 @@ <title>Wicket 4520</title> </head> <body> - <div id="_message_attr_1" title="Some title"> + <div id="_message_attr_" title="Some title"> <div>Inner div <span>A Label</span> </div> http://git-wip-us.apache.org/repos/asf/wicket/blob/88961c1a/wicket-core/src/test/java/org/apache/wicket/markup/html/internal/TogglePageTest.java ---------------------------------------------------------------------- diff --git a/wicket-core/src/test/java/org/apache/wicket/markup/html/internal/TogglePageTest.java b/wicket-core/src/test/java/org/apache/wicket/markup/html/internal/TogglePageTest.java index 0927a3c..05fb167 100644 --- a/wicket-core/src/test/java/org/apache/wicket/markup/html/internal/TogglePageTest.java +++ b/wicket-core/src/test/java/org/apache/wicket/markup/html/internal/TogglePageTest.java @@ -139,10 +139,10 @@ public class TogglePageTest extends WicketTestCase String inlineEnclosureIdPrefix = "InlineEnclosure-"; String inlineEnclosureHiddenPattern = "<tr id=\"" + inlineEnclosureIdPrefix + - "1\" style=\"display:none\"></tr>"; + "0\" style=\"display:none\"></tr>"; String inlineEnclosureVisiblePattern = "<tr bgcolor=\"red\" id=\"" + - inlineEnclosureIdPrefix + "1\">"; + inlineEnclosureIdPrefix + "0\">"; { // On
