Author: ivaynberg
Date: Tue Apr 15 11:54:39 2008
New Revision: 648377
URL: http://svn.apache.org/viewvc?rev=648377&view=rev
Log:
WICKET-1536
Added:
wicket/branches/wicket-1.3.x/jdk-1.4/wicket/src/test/java/org/apache/wicket/markup/html/internal/EnclosurePage_6.html
(with props)
wicket/branches/wicket-1.3.x/jdk-1.4/wicket/src/test/java/org/apache/wicket/markup/html/internal/EnclosurePage_6.java
(with props)
Modified:
wicket/branches/wicket-1.3.x/jdk-1.4/wicket/src/main/java/org/apache/wicket/markup/html/internal/Enclosure.java
wicket/branches/wicket-1.3.x/jdk-1.4/wicket/src/test/java/org/apache/wicket/markup/html/internal/EnclosureTest.java
Modified:
wicket/branches/wicket-1.3.x/jdk-1.4/wicket/src/main/java/org/apache/wicket/markup/html/internal/Enclosure.java
URL:
http://svn.apache.org/viewvc/wicket/branches/wicket-1.3.x/jdk-1.4/wicket/src/main/java/org/apache/wicket/markup/html/internal/Enclosure.java?rev=648377&r1=648376&r2=648377&view=diff
==============================================================================
---
wicket/branches/wicket-1.3.x/jdk-1.4/wicket/src/main/java/org/apache/wicket/markup/html/internal/Enclosure.java
(original)
+++
wicket/branches/wicket-1.3.x/jdk-1.4/wicket/src/main/java/org/apache/wicket/markup/html/internal/Enclosure.java
Tue Apr 15 11:54:39 2008
@@ -16,6 +16,11 @@
*/
package org.apache.wicket.markup.html.internal;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Map.Entry;
+
import org.apache.wicket.Component;
import org.apache.wicket.MarkupContainer;
import org.apache.wicket.WicketRuntimeException;
@@ -86,6 +91,9 @@
/** Id of the child component that will control visibility of the
enclosure */
private final CharSequence childId;
+ /** Map of component->boolean that tracks original visibility allowed
flag values */
+ private transient Map originalVisibilityStatus;
+
/**
* Construct.
*
@@ -185,6 +193,7 @@
setVisible(controller.determineVisibility());
// transfer visibility to direct children
+ originalVisibilityStatus = new HashMap();
DirectChildTagIterator it = new
DirectChildTagIterator(markupStream, openTag);
MarkupContainer controllerParent = getEnclosureParent();
while (it.hasNext())
@@ -193,6 +202,7 @@
Component child = controllerParent.get(t.getId());
if (child != null)
{
+ originalVisibilityStatus.put(child,
Boolean.valueOf(child.isVisibilityAllowed()));
child.setVisibilityAllowed(isVisible());
}
}
@@ -206,6 +216,24 @@
{
markupStream.skipToMatchingCloseTag(openTag);
}
+ }
+
+ protected void onDetach()
+ {
+ if (originalVisibilityStatus != null)
+ {
+ // restore original visibility statuses
+ Iterator it =
originalVisibilityStatus.entrySet().iterator();
+ while (it.hasNext())
+ {
+ final Map.Entry entry = (Entry)it.next();
+ final Component c = (Component)entry.getKey();
+ final boolean vis =
((Boolean)entry.getValue()).booleanValue();
+ c.setVisibilityAllowed(vis);
+ }
+ originalVisibilityStatus = null;
+ }
+ super.onDetach();
}
/**
Added:
wicket/branches/wicket-1.3.x/jdk-1.4/wicket/src/test/java/org/apache/wicket/markup/html/internal/EnclosurePage_6.html
URL:
http://svn.apache.org/viewvc/wicket/branches/wicket-1.3.x/jdk-1.4/wicket/src/test/java/org/apache/wicket/markup/html/internal/EnclosurePage_6.html?rev=648377&view=auto
==============================================================================
---
wicket/branches/wicket-1.3.x/jdk-1.4/wicket/src/test/java/org/apache/wicket/markup/html/internal/EnclosurePage_6.html
(added)
+++
wicket/branches/wicket-1.3.x/jdk-1.4/wicket/src/test/java/org/apache/wicket/markup/html/internal/EnclosurePage_6.html
Tue Apr 15 11:54:39 2008
@@ -0,0 +1,9 @@
+<html>
+<body>
+<link wicket:id="link">toggle</link>
+<wicket:enclosure child="label1">
+<span wicket:id="label1"></span>
+<span wicket:id="label2"></span>
+</wicket:enclosure>
+</body>
+</html>
\ No newline at end of file
Propchange:
wicket/branches/wicket-1.3.x/jdk-1.4/wicket/src/test/java/org/apache/wicket/markup/html/internal/EnclosurePage_6.html
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added:
wicket/branches/wicket-1.3.x/jdk-1.4/wicket/src/test/java/org/apache/wicket/markup/html/internal/EnclosurePage_6.java
URL:
http://svn.apache.org/viewvc/wicket/branches/wicket-1.3.x/jdk-1.4/wicket/src/test/java/org/apache/wicket/markup/html/internal/EnclosurePage_6.java?rev=648377&view=auto
==============================================================================
---
wicket/branches/wicket-1.3.x/jdk-1.4/wicket/src/test/java/org/apache/wicket/markup/html/internal/EnclosurePage_6.java
(added)
+++
wicket/branches/wicket-1.3.x/jdk-1.4/wicket/src/test/java/org/apache/wicket/markup/html/internal/EnclosurePage_6.java
Tue Apr 15 11:54:39 2008
@@ -0,0 +1,58 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.wicket.markup.html.internal;
+
+import org.apache.wicket.markup.html.WebPage;
+import org.apache.wicket.markup.html.basic.Label;
+import org.apache.wicket.markup.html.link.Link;
+
+/**
+ * @author ivaynberg
+ */
+public class EnclosurePage_6 extends WebPage
+{
+ private int counter;
+
+ /**
+ * Constructor
+ */
+ public EnclosurePage_6()
+ {
+ add(new Link("link")
+ {
+ private static final long serialVersionUID = 1L;
+
+ public void onClick()
+ {
+ counter++;
+ }
+
+ });
+
+ add(new Label("label1", "content1")
+ {
+ private static final long serialVersionUID = 1L;
+
+ public boolean isVisible()
+ {
+ return counter % 2 == 0;
+ }
+ });
+
+ add(new Label("label2", "content2"));
+ }
+}
Propchange:
wicket/branches/wicket-1.3.x/jdk-1.4/wicket/src/test/java/org/apache/wicket/markup/html/internal/EnclosurePage_6.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified:
wicket/branches/wicket-1.3.x/jdk-1.4/wicket/src/test/java/org/apache/wicket/markup/html/internal/EnclosureTest.java
URL:
http://svn.apache.org/viewvc/wicket/branches/wicket-1.3.x/jdk-1.4/wicket/src/test/java/org/apache/wicket/markup/html/internal/EnclosureTest.java?rev=648377&r1=648376&r2=648377&view=diff
==============================================================================
---
wicket/branches/wicket-1.3.x/jdk-1.4/wicket/src/test/java/org/apache/wicket/markup/html/internal/EnclosureTest.java
(original)
+++
wicket/branches/wicket-1.3.x/jdk-1.4/wicket/src/test/java/org/apache/wicket/markup/html/internal/EnclosureTest.java
Tue Apr 15 11:54:39 2008
@@ -109,4 +109,30 @@
executeTest(EnclosurePage_5.class, new
PageParameters("visible=true"),
"EnclosurePageExpectedResult_5-1.html");
}
+
+ /**
+ * Tests visibility of children after enclosure has been made hidden
and visible again
+ *
+ * @throws Exception
+ */
+ public void testVisibilityOfChildren() throws Exception
+ {
+ // render with enclosure initally visible
+ tester.startPage(EnclosurePage_6.class);
+ String doc = tester.getServletResponse().getDocument();
+ assertTrue(doc.contains("content1"));
+ assertTrue(doc.contains("content2"));
+
+ // render with enclosure hidden
+ tester.clickLink("link");
+ doc = tester.getServletResponse().getDocument();
+ assertFalse(doc.contains("content1"));
+ assertFalse(doc.contains("content2"));
+
+ // render with enclosure visible again
+ tester.clickLink("link");
+ doc = tester.getServletResponse().getDocument();
+ assertTrue(doc.contains("content1"));
+ assertTrue(doc.contains("content2"));
+ }
}