You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@wicket.apache.org by jd...@apache.org on 2011/04/08 08:08:06 UTC
svn commit: r1090127 [1/2] - in /wicket/trunk/wicket-core/src:
main/java/org/apache/wicket/ main/java/org/apache/wicket/ajax/
main/java/org/apache/wicket/markup/
main/java/org/apache/wicket/markup/html/internal/
main/java/org/apache/wicket/markup/parse...
Author: jdonnerstag
Date: Fri Apr 8 06:08:05 2011
New Revision: 1090127
URL: http://svn.apache.org/viewvc?rev=1090127&view=rev
Log:
fixed WICKET-3527 Simplified visibility control of Enclosures in Ajax requests
Issue: WICKET-3527
Added:
wicket/trunk/wicket-core/src/main/java/org/apache/wicket/markup/html/internal/InlineEnclosure.java
wicket/trunk/wicket-core/src/main/java/org/apache/wicket/markup/parser/filter/InlineEnclosureHandler.java
wicket/trunk/wicket-core/src/main/java/org/apache/wicket/protocol/http/AjaxEnclosureListener.java
wicket/trunk/wicket-core/src/test/java/org/apache/wicket/markup/html/internal/AjaxEnclosurePage_1.html
wicket/trunk/wicket-core/src/test/java/org/apache/wicket/markup/html/internal/AjaxEnclosurePage_1.java
wicket/trunk/wicket-core/src/test/java/org/apache/wicket/markup/html/internal/AjaxEnclosurePage_2.html
wicket/trunk/wicket-core/src/test/java/org/apache/wicket/markup/html/internal/AjaxEnclosurePage_2.java
wicket/trunk/wicket-core/src/test/java/org/apache/wicket/markup/html/internal/AjaxEnclosurePage_3.html
wicket/trunk/wicket-core/src/test/java/org/apache/wicket/markup/html/internal/AjaxEnclosurePage_3.java
wicket/trunk/wicket-core/src/test/java/org/apache/wicket/markup/html/internal/AjaxEnclosureTest.java
wicket/trunk/wicket-core/src/test/java/org/apache/wicket/markup/html/internal/FullReloadPage.html
wicket/trunk/wicket-core/src/test/java/org/apache/wicket/markup/html/internal/FullReloadPage.java
wicket/trunk/wicket-core/src/test/java/org/apache/wicket/markup/html/internal/InlineEnclosureAjaxPage.html
wicket/trunk/wicket-core/src/test/java/org/apache/wicket/markup/html/internal/InlineEnclosureAjaxPage.java
wicket/trunk/wicket-core/src/test/java/org/apache/wicket/markup/html/internal/InlineEnclosurePageExpectedResult_1.html
wicket/trunk/wicket-core/src/test/java/org/apache/wicket/markup/html/internal/InlineEnclosurePageExpectedResult_2.html
wicket/trunk/wicket-core/src/test/java/org/apache/wicket/markup/html/internal/InlineEnclosurePage_1.html
wicket/trunk/wicket-core/src/test/java/org/apache/wicket/markup/html/internal/InlineEnclosurePage_1.java
wicket/trunk/wicket-core/src/test/java/org/apache/wicket/markup/html/internal/InlineEnclosurePage_2.html
wicket/trunk/wicket-core/src/test/java/org/apache/wicket/markup/html/internal/InlineEnclosurePage_2.java
wicket/trunk/wicket-core/src/test/java/org/apache/wicket/markup/html/internal/InlineEnclosurePanelPage.html
wicket/trunk/wicket-core/src/test/java/org/apache/wicket/markup/html/internal/InlineEnclosurePanelPage.java
wicket/trunk/wicket-core/src/test/java/org/apache/wicket/markup/html/internal/InlineEnclosurePanelPageExpectedResult.html
wicket/trunk/wicket-core/src/test/java/org/apache/wicket/markup/html/internal/InlineEnclosureTest.java
wicket/trunk/wicket-core/src/test/java/org/apache/wicket/markup/html/internal/InlineEnclosureWithAdditionalAjaxTargetPage.html
wicket/trunk/wicket-core/src/test/java/org/apache/wicket/markup/html/internal/InlineEnclosureWithAdditionalAjaxTargetPage.java
wicket/trunk/wicket-core/src/test/java/org/apache/wicket/markup/html/internal/SimplePanel2.html
wicket/trunk/wicket-core/src/test/java/org/apache/wicket/markup/html/internal/SimplePanel2.java
wicket/trunk/wicket-core/src/test/java/org/apache/wicket/markup/html/internal/TogglePageTests.java
wicket/trunk/wicket-core/src/test/java/org/apache/wicket/markup/html/internal/TraditionalEnclosureAjaxPage.html
wicket/trunk/wicket-core/src/test/java/org/apache/wicket/markup/html/internal/TraditionalEnclosureAjaxPage.java
Modified:
wicket/trunk/wicket-core/src/main/java/org/apache/wicket/Application.java
wicket/trunk/wicket-core/src/main/java/org/apache/wicket/Component.java
wicket/trunk/wicket-core/src/main/java/org/apache/wicket/MarkupContainer.java
wicket/trunk/wicket-core/src/main/java/org/apache/wicket/ajax/AjaxRequestTarget.java
wicket/trunk/wicket-core/src/main/java/org/apache/wicket/markup/MarkupParser.java
wicket/trunk/wicket-core/src/main/java/org/apache/wicket/markup/html/internal/Enclosure.java
wicket/trunk/wicket-core/src/main/java/org/apache/wicket/protocol/http/WebApplication.java
Modified: wicket/trunk/wicket-core/src/main/java/org/apache/wicket/Application.java
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket-core/src/main/java/org/apache/wicket/Application.java?rev=1090127&r1=1090126&r2=1090127&view=diff
==============================================================================
--- wicket/trunk/wicket-core/src/main/java/org/apache/wicket/Application.java (original)
+++ wicket/trunk/wicket-core/src/main/java/org/apache/wicket/Application.java Fri Apr 8 06:08:05 2011
@@ -41,6 +41,7 @@ import org.apache.wicket.markup.html.IHe
import org.apache.wicket.markup.html.IHeaderResponseDecorator;
import org.apache.wicket.markup.html.image.resource.DefaultButtonImageResourceFactory;
import org.apache.wicket.markup.parser.filter.EnclosureHandler;
+import org.apache.wicket.markup.parser.filter.InlineEnclosureHandler;
import org.apache.wicket.markup.parser.filter.RelativePathPrefixHandler;
import org.apache.wicket.markup.parser.filter.WicketLinkTagHandler;
import org.apache.wicket.markup.parser.filter.WicketMessageTagHandler;
@@ -680,6 +681,7 @@ public abstract class Application implem
pageSettings.addComponentResolver(new FragmentResolver());
pageSettings.addComponentResolver(new RelativePathPrefixHandler());
pageSettings.addComponentResolver(new EnclosureHandler());
+ pageSettings.addComponentResolver(new InlineEnclosureHandler());
pageSettings.addComponentResolver(new WicketContainerResolver());
// Install button image resource factory
Modified: wicket/trunk/wicket-core/src/main/java/org/apache/wicket/Component.java
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket-core/src/main/java/org/apache/wicket/Component.java?rev=1090127&r1=1090126&r2=1090127&view=diff
==============================================================================
--- wicket/trunk/wicket-core/src/main/java/org/apache/wicket/Component.java (original)
+++ wicket/trunk/wicket-core/src/main/java/org/apache/wicket/Component.java Fri Apr 8 06:08:05 2011
@@ -4152,7 +4152,7 @@ public abstract class Component
/**
*
*/
- void onAfterRenderChildren()
+ protected void onAfterRenderChildren()
{
}
Modified: wicket/trunk/wicket-core/src/main/java/org/apache/wicket/MarkupContainer.java
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket-core/src/main/java/org/apache/wicket/MarkupContainer.java?rev=1090127&r1=1090126&r2=1090127&view=diff
==============================================================================
--- wicket/trunk/wicket-core/src/main/java/org/apache/wicket/MarkupContainer.java (original)
+++ wicket/trunk/wicket-core/src/main/java/org/apache/wicket/MarkupContainer.java Fri Apr 8 06:08:05 2011
@@ -34,6 +34,7 @@ import org.apache.wicket.markup.MarkupSt
import org.apache.wicket.markup.MarkupType;
import org.apache.wicket.markup.WicketTag;
import org.apache.wicket.markup.html.border.Border;
+import org.apache.wicket.markup.html.internal.InlineEnclosure;
import org.apache.wicket.markup.resolver.ComponentResolvers;
import org.apache.wicket.model.IComponentInheritedModel;
import org.apache.wicket.model.IModel;
@@ -1412,6 +1413,10 @@ public abstract class MarkupContainer ex
{
autoAdd(component, markupStream);
}
+ else if (component != null)
+ {
+ component.setMarkup(markupStream.getMarkupFragment());
+ }
}
// Failed to find it?
@@ -1606,11 +1611,6 @@ public abstract class MarkupContainer ex
}
}
-
- /**
- *
- * @see org.apache.wicket.Component#detachChildren()
- */
@Override
void detachChildren()
{
@@ -1624,12 +1624,16 @@ public abstract class MarkupContainer ex
Component component = (Component)child;
component.detach();
- if (component.isAuto())
+ // We need to keep InlineEnclosures for Ajax request handling.
+ // TODO this is really ugly. Feature request for 1.5: change auto-component that
+ // they don't need to be removed anymore.
+ if (component.isAuto() && !(component instanceof InlineEnclosure))
{
children_remove(i);
}
}
}
+
if (children instanceof ChildList)
{
ChildList lst = (ChildList)children;
@@ -1737,12 +1741,8 @@ public abstract class MarkupContainer ex
});
}
- /**
- *
- * @see org.apache.wicket.Component#onAfterRenderChildren()
- */
@Override
- void onAfterRenderChildren()
+ protected void onAfterRenderChildren()
{
// Loop through child components
final Iterator<? extends Component> iter = iterator();
Modified: wicket/trunk/wicket-core/src/main/java/org/apache/wicket/ajax/AjaxRequestTarget.java
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket-core/src/main/java/org/apache/wicket/ajax/AjaxRequestTarget.java?rev=1090127&r1=1090126&r2=1090127&view=diff
==============================================================================
--- wicket/trunk/wicket-core/src/main/java/org/apache/wicket/ajax/AjaxRequestTarget.java (original)
+++ wicket/trunk/wicket-core/src/main/java/org/apache/wicket/ajax/AjaxRequestTarget.java Fri Apr 8 06:08:05 2011
@@ -16,7 +16,6 @@
*/
package org.apache.wicket.ajax;
-import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
@@ -54,6 +53,7 @@ import org.apache.wicket.request.resourc
import org.apache.wicket.response.StringResponse;
import org.apache.wicket.response.filter.IResponseFilter;
import org.apache.wicket.util.lang.Args;
+import org.apache.wicket.util.lang.Generics;
import org.apache.wicket.util.string.AppendingStringBuffer;
import org.apache.wicket.util.string.Strings;
import org.apache.wicket.util.visit.IVisit;
@@ -233,11 +233,11 @@ public class AjaxRequestTarget implement
}
}
- private static final Logger LOG = LoggerFactory.getLogger(AjaxRequestTarget.class);
+ private static final Logger log = LoggerFactory.getLogger(AjaxRequestTarget.class);
- private final List<CharSequence> appendJavaScripts = new ArrayList<CharSequence>();
+ private final List<CharSequence> appendJavaScripts = Generics.newArrayList();
- private final List<CharSequence> domReadyJavaScripts = new ArrayList<CharSequence>();
+ private final List<CharSequence> domReadyJavaScripts = Generics.newArrayList();
/**
* Create a response for component body and javascript that will escape output to make it safe
@@ -255,7 +255,7 @@ public class AjaxRequestTarget implement
private final Map<String, Component> markupIdToComponent = new LinkedHashMap<String, Component>();
/** */
- private final List<CharSequence> prependJavaScripts = new ArrayList<CharSequence>();
+ private final List<CharSequence> prependJavaScripts = Generics.newArrayList();
/** a list of listeners */
private List<IListener> listeners = null;
@@ -267,15 +267,6 @@ public class AjaxRequestTarget implement
private final Page page;
/**
- *
- * @see org.apache.wicket.request.handler.IPageRequestHandler#getPage()
- */
- public Page getPage()
- {
- return page;
- }
-
- /**
* Constructor
*
* @param page
@@ -290,6 +281,14 @@ public class AjaxRequestTarget implement
}
/**
+ * @see org.apache.wicket.request.handler.IPageRequestHandler#getPage()
+ */
+ public Page getPage()
+ {
+ return page;
+ }
+
+ /**
* Adds a listener to this target
*
* @param listener
@@ -366,10 +365,8 @@ public class AjaxRequestTarget implement
{
for (final Component component : components)
{
- if (component == null)
- {
- throw new IllegalArgumentException("component cannot be null");
- }
+ Args.notNull(component, "component");
+
if (component.getOutputMarkupId() == false)
{
throw new IllegalArgumentException(
@@ -402,21 +399,15 @@ public class AjaxRequestTarget implement
*
* @param markupId
* id of client-side dom element that will be updated
- *
* @param component
* component to be rendered
*/
- public final void add(Component component, String markupId)
+ public final void add(final Component component, final String markupId)
{
- if (Strings.isEmpty(markupId))
- {
- throw new IllegalArgumentException("markupId cannot be empty");
- }
- if (component == null)
- {
- throw new IllegalArgumentException("component cannot be null");
- }
- else if (component instanceof Page)
+ Args.notEmpty(markupId, "markupId");
+ Args.notNull(component, "component");
+
+ if (component instanceof Page)
{
if (component != page)
{
@@ -428,7 +419,8 @@ public class AjaxRequestTarget implement
throw new IllegalArgumentException(
"Component " +
component.getClass().getName() +
- " has been added to the target. This component is a repeater and cannot be repainted via ajax directly. Instead add its parent or another markup container higher in the hierarchy.");
+ " has been added to the target. This component is a repeater and cannot be repainted via ajax directly. " +
+ "Instead add its parent or another markup container higher in the hierarchy.");
}
component.setMarkupId(markupId);
@@ -471,10 +463,7 @@ public class AjaxRequestTarget implement
*/
public final void appendJavaScript(CharSequence javascript)
{
- if (javascript == null)
- {
- throw new IllegalArgumentException("javascript cannot be null");
- }
+ Args.notNull(javascript, "javascript");
appendJavaScripts.add(javascript);
}
@@ -532,10 +521,7 @@ public class AjaxRequestTarget implement
*/
public final void prependJavaScript(CharSequence javascript)
{
- if (javascript == null)
- {
- throw new IllegalArgumentException("javascript cannot be null");
- }
+ Args.notNull(javascript, "javascript");
prependJavaScripts.add(javascript);
}
@@ -579,8 +565,7 @@ public class AjaxRequestTarget implement
try
{
- RequestCycle rc = (RequestCycle)requestCycle;
-
+ final RequestCycle rc = (RequestCycle)requestCycle;
final WebResponse response = (WebResponse)requestCycle.getResponse();
if (markupIdToComponent.values().contains(page))
@@ -943,12 +928,8 @@ public class AjaxRequestTarget implement
if (page == null)
{
// dont throw an exception but just ignore this component, somehow
- // it got
- // removed from the page.
- // throw new IllegalStateException(
- // "Ajax request attempted on a component that is not associated
- // with a Page");
- LOG.debug("component: " + component + " with markupid: " + markupId +
+ // it got removed from the page.
+ log.debug("component: " + component + " with markupid: " + markupId +
" not rendered because it was already removed from page");
return;
}
@@ -1021,7 +1002,7 @@ public class AjaxRequestTarget implement
{
if (headerRendering == false)
{
- LOG.debug("Only methods that can be called on IHeaderResponse outside renderHead() are renderOnLoadJavaScript and renderOnDomReadyJavaScript");
+ log.debug("Only methods that can be called on IHeaderResponse outside renderHead() are renderOnLoadJavaScript and renderOnDomReadyJavaScript");
}
return headerRendering;
@@ -1356,6 +1337,4 @@ public class AjaxRequestTarget implement
{
return page.getPageParameters();
}
-
-
}
Modified: wicket/trunk/wicket-core/src/main/java/org/apache/wicket/markup/MarkupParser.java
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket-core/src/main/java/org/apache/wicket/markup/MarkupParser.java?rev=1090127&r1=1090126&r2=1090127&view=diff
==============================================================================
--- wicket/trunk/wicket-core/src/main/java/org/apache/wicket/markup/MarkupParser.java (original)
+++ wicket/trunk/wicket-core/src/main/java/org/apache/wicket/markup/MarkupParser.java Fri Apr 8 06:08:05 2011
@@ -26,6 +26,7 @@ import org.apache.wicket.markup.parser.f
import org.apache.wicket.markup.parser.filter.HeadForceTagIdHandler;
import org.apache.wicket.markup.parser.filter.HtmlHandler;
import org.apache.wicket.markup.parser.filter.HtmlHeaderSectionHandler;
+import org.apache.wicket.markup.parser.filter.InlineEnclosureHandler;
import org.apache.wicket.markup.parser.filter.OpenCloseTagExpander;
import org.apache.wicket.markup.parser.filter.RelativePathPrefixHandler;
import org.apache.wicket.markup.parser.filter.StyleAndScriptIdentifier;
@@ -182,6 +183,7 @@ public class MarkupParser extends Abstra
filters.add(new OpenCloseTagExpander());
filters.add(new RelativePathPrefixHandler());
filters.add(new EnclosureHandler());
+ filters.add(new InlineEnclosureHandler());
filters.add(new StyleAndScriptIdentifier(markup));
filters.add(new ConditionalCommentFilter());
Modified: wicket/trunk/wicket-core/src/main/java/org/apache/wicket/markup/html/internal/Enclosure.java
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket-core/src/main/java/org/apache/wicket/markup/html/internal/Enclosure.java?rev=1090127&r1=1090126&r2=1090127&view=diff
==============================================================================
--- wicket/trunk/wicket-core/src/main/java/org/apache/wicket/markup/html/internal/Enclosure.java (original)
+++ wicket/trunk/wicket-core/src/main/java/org/apache/wicket/markup/html/internal/Enclosure.java Fri Apr 8 06:08:05 2011
@@ -116,20 +116,27 @@ public class Enclosure extends WebMarkup
this.childId = childId;
}
+ /**
+ *
+ * @return child id
+ */
+ public final String getChildId()
+ {
+ return childId.toString();
+ }
+
@Override
protected void onInitialize()
{
super.onInitialize();
- // enclosure's parent container
- MarkupContainer container = getEnclosureParent();
-
- // clear the cache
- childComponent = null;
-
// get Child Component. If not "added", ask a resolver to find it.
- childComponent = getChildComponent(new MarkupStream(getMarkup()), container);
- checkChildComponent(childComponent);
+ childComponent = getChildComponent(new MarkupStream(getMarkup()), getEnclosureParent());
+ }
+
+ protected final Component getChild()
+ {
+ return childComponent;
}
/**
@@ -137,7 +144,7 @@ public class Enclosure extends WebMarkup
*
* @return enclosure's parent markup container
*/
- private MarkupContainer getEnclosureParent()
+ protected MarkupContainer getEnclosureParent()
{
MarkupContainer parent = getParent();
while ((parent != null) && parent.isAuto())
@@ -202,7 +209,7 @@ public class Enclosure extends WebMarkup
*/
private Component getChildComponent(final MarkupStream markupStream, MarkupContainer container)
{
- Component controller = container.get(childId.toString());
+ Component controller = getEnclosureParent().get(getChildId());
if (controller == null)
{
int orgIndex = markupStream.getCurrentIndex();
@@ -238,6 +245,8 @@ public class Enclosure extends WebMarkup
markupStream.setCurrentIndex(orgIndex);
}
}
+
+ checkChildComponent(controller);
return controller;
}
@@ -280,9 +289,6 @@ public class Enclosure extends WebMarkup
this.enclosure = enclosure;
}
- /**
- * @see org.apache.wicket.application.IComponentOnBeforeRenderListener#onBeforeRender(org.apache.wicket.Component)
- */
public void onAfterRender(final Component component)
{
if (log.isWarnEnabled())
Added: wicket/trunk/wicket-core/src/main/java/org/apache/wicket/markup/html/internal/InlineEnclosure.java
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket-core/src/main/java/org/apache/wicket/markup/html/internal/InlineEnclosure.java?rev=1090127&view=auto
==============================================================================
--- wicket/trunk/wicket-core/src/main/java/org/apache/wicket/markup/html/internal/InlineEnclosure.java (added)
+++ wicket/trunk/wicket-core/src/main/java/org/apache/wicket/markup/html/internal/InlineEnclosure.java Fri Apr 8 06:08:05 2011
@@ -0,0 +1,82 @@
+/*
+ * 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.ComponentTag;
+import org.apache.wicket.markup.parser.filter.InlineEnclosureHandler;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+/**
+ * An InlineEnclosure are automatically created by Wicket. Do not create it yourself. An
+ * InlineEnclosure container is created when <tr wicket:enclosure="controllingChildId"> (any
+ * html tag which can contain other html tags can be used in place of <tr>) is found in the
+ * markup. The child component (it's id defined as the value of the attribute, in the example,
+ * 'controllingChildId') controls the visibility of the whole enclosure and it's children. This also
+ * works in Ajax calls without extra markup or java code.
+ *
+ * @see EnclosureResolver
+ * @see InlineEnclosureHandler
+ *
+ * @author Joonas Hamalainen
+ * @author Juergen Donnerstag
+ */
+public class InlineEnclosure extends Enclosure
+{
+ private static final long serialVersionUID = 1L;
+
+ private static final Logger log = LoggerFactory.getLogger(InlineEnclosure.class);
+
+ /**
+ * Construct.
+ *
+ * @param id
+ * @param childId
+ * @param isInlineEnclosure
+ */
+ public InlineEnclosure(final String id, final String childId)
+ {
+ super(id, childId);
+
+ // ensure that the Enclosure is ready for ajax updates
+ setOutputMarkupId(true);
+ setOutputMarkupPlaceholderTag(true);
+ setMarkupId(getId());
+ }
+
+ @Override
+ protected void onComponentTag(final ComponentTag tag)
+ {
+ // remove the wicket:enclosure attribute
+ tag.remove(InlineEnclosureHandler.INLINE_ENCLOSURE_ATTRIBUTE_NAME);
+
+ super.onComponentTag(tag);
+ }
+
+ /**
+ * Update the visibility of this In-line enclosure with that of the controlling child.
+ *
+ * @return the new visibility setting.
+ */
+ public boolean updateVisibility()
+ {
+ boolean visible = getChild().isVisible();
+ setVisible(visible);
+ return visible;
+ }
+}
Added: wicket/trunk/wicket-core/src/main/java/org/apache/wicket/markup/parser/filter/InlineEnclosureHandler.java
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket-core/src/main/java/org/apache/wicket/markup/parser/filter/InlineEnclosureHandler.java?rev=1090127&view=auto
==============================================================================
--- wicket/trunk/wicket-core/src/main/java/org/apache/wicket/markup/parser/filter/InlineEnclosureHandler.java (added)
+++ wicket/trunk/wicket-core/src/main/java/org/apache/wicket/markup/parser/filter/InlineEnclosureHandler.java Fri Apr 8 06:08:05 2011
@@ -0,0 +1,191 @@
+/*
+ * 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.parser.filter;
+
+import java.text.ParseException;
+import java.util.Stack;
+
+import org.apache.wicket.Component;
+import org.apache.wicket.MarkupContainer;
+import org.apache.wicket.markup.ComponentTag;
+import org.apache.wicket.markup.MarkupElement;
+import org.apache.wicket.markup.MarkupStream;
+import org.apache.wicket.markup.WicketTag;
+import org.apache.wicket.markup.html.internal.InlineEnclosure;
+import org.apache.wicket.markup.parser.AbstractMarkupFilter;
+import org.apache.wicket.markup.resolver.IComponentResolver;
+import org.apache.wicket.util.string.Strings;
+
+
+/**
+ * This is a markup inline filter. It identifies enclosures as attribute, for example: <tr
+ * wicket:enclosure="">. The <tr> tag used in the example can be replaced with any html tag
+ * that can contain child elements. If the 'child' attribute is empty it determines the wicket:id of
+ * the child component automatically by analyzing the wicket component (in this case one wicket
+ * component is allowed) in between the open and close tags. If the enclosure tag has a 'child'
+ * attribute like <code><tr
+ * wicket:enclosure="controllingChildId"></code> than more than just one wicket component inside
+ * the enclosure tags are allowed and the child component which determines the visibility of the
+ * enclosure is identified by the 'child' attribute value which must be equal to the relative child
+ * id path.
+ *
+ * @see EnclosureResolver
+ * @see InlineEnclosure
+ *
+ * @author Joonas Hamalainen
+ * @author Juergen Donnerstag
+ */
+public final class InlineEnclosureHandler extends AbstractMarkupFilter
+ implements
+ IComponentResolver
+{
+ private static final long serialVersionUID = 1L;
+
+ /** The Component id prefix. */
+ public final static String INLINE_ENCLOSURE_ID_PREFIX = "InlineEnclosure-";
+
+ /** Attribute to identify inline enclosures */
+ public final static String INLINE_ENCLOSURE_ATTRIBUTE_NAME = "wicket:enclosure";
+
+ /** enclosures inside enclosures */
+ private Stack<ComponentTag> enclosures;
+
+ /**
+ * Construct.
+ */
+ public InlineEnclosureHandler()
+ {
+ }
+
+ @Override
+ protected MarkupElement onComponentTag(final ComponentTag tag) throws ParseException
+ {
+ // We only need ComponentTags
+ if (tag instanceof WicketTag)
+ {
+ return tag;
+ }
+
+ // Has wicket:enclosure attribute?
+ String enclosureAttr = getInlineEnclosureAttribute(tag);
+ if (enclosureAttr != null)
+ {
+ if (tag.isOpen())
+ {
+ // Make sure 'wicket:id' and 'id' are consistent
+ String htmlId = tag.getAttribute("id");
+ if ((tag.getId() != null) && !Strings.isEmpty(htmlId) &&
+ !htmlId.equals(tag.getId()))
+ {
+ throw new ParseException(
+ "Make sure that 'id' and 'wicket:id' are the same if both are provided. Tag:" +
+ tag.toString(), tag.getPos());
+ }
+
+ // if it doesn't have a wicket-id already, than assign one now.
+ if (Strings.isEmpty(tag.getId()))
+ {
+ if (Strings.isEmpty(htmlId))
+ {
+ tag.setId(INLINE_ENCLOSURE_ID_PREFIX);
+ }
+ else
+ {
+ tag.setId(htmlId);
+ }
+
+ tag.setAutoComponentTag(true);
+ tag.setModified(true);
+ }
+
+ // Put the enclosure on the stack. The most current one will be on top
+ if (enclosures == null)
+ {
+ enclosures = new Stack<ComponentTag>();
+ }
+ enclosures.push(tag);
+ }
+ else
+ {
+ throw new ParseException(
+ "Open-close tags don't make sense for InlineEnclosure. Tag:" + tag.toString(),
+ tag.getPos());
+ }
+ }
+ // Are we within an enclosure?
+ else if ((enclosures != null) && (enclosures.size() > 0))
+ {
+ // In case the enclosure tag did not provide a child component id, than assign the
+ // first ComponentTag's id found as the controlling child to the enclosure.
+ if (tag.isOpen() && (tag.getId() != null) && !(tag instanceof WicketTag) &&
+ !tag.isAutoComponentTag())
+ {
+ for (int i = enclosures.size() - 1; i >= 0; i--)
+ {
+ ComponentTag lastEnclosure = enclosures.get(i);
+ String attr = getInlineEnclosureAttribute(lastEnclosure);
+ if (Strings.isEmpty(attr) == true)
+ {
+ lastEnclosure.getAttributes().put(INLINE_ENCLOSURE_ATTRIBUTE_NAME,
+ tag.getId());
+ lastEnclosure.setModified(true);
+ }
+ }
+ }
+ else if (tag.isClose() && tag.closes(enclosures.peek()))
+ {
+ ComponentTag lastEnclosure = enclosures.pop();
+ String attr = getInlineEnclosureAttribute(lastEnclosure);
+ if (Strings.isEmpty(attr) == true)
+ {
+ throw new ParseException("Did not find any child for InlineEnclosure. Tag:" +
+ lastEnclosure.toString(), tag.getPos());
+ }
+ }
+ }
+
+ return tag;
+ }
+
+ /**
+ * @param tag
+ * @return The wicket:enclosure attribute or null if not found
+ */
+ public final static String getInlineEnclosureAttribute(final ComponentTag tag)
+ {
+ return tag.getAttributes().getString(INLINE_ENCLOSURE_ATTRIBUTE_NAME);
+ }
+
+ public Component resolve(final MarkupContainer container, final MarkupStream markupStream,
+ final ComponentTag tag)
+ {
+ String inlineEnclosureChildId = getInlineEnclosureAttribute(tag);
+ if (Strings.isEmpty(inlineEnclosureChildId) == false)
+ {
+ String id = tag.getId();
+ if (id.equals(INLINE_ENCLOSURE_ID_PREFIX))
+ {
+ id = id + container.getPage().getAutoIndex();
+ }
+ // Yes, we handled the tag
+ return new InlineEnclosure(id, inlineEnclosureChildId);
+ }
+
+ // We were not able to handle the tag
+ return null;
+ }
+}
Added: wicket/trunk/wicket-core/src/main/java/org/apache/wicket/protocol/http/AjaxEnclosureListener.java
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket-core/src/main/java/org/apache/wicket/protocol/http/AjaxEnclosureListener.java?rev=1090127&view=auto
==============================================================================
--- wicket/trunk/wicket-core/src/main/java/org/apache/wicket/protocol/http/AjaxEnclosureListener.java (added)
+++ wicket/trunk/wicket-core/src/main/java/org/apache/wicket/protocol/http/AjaxEnclosureListener.java Fri Apr 8 06:08:05 2011
@@ -0,0 +1,114 @@
+/*
+ * 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.protocol.http;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.wicket.Component;
+import org.apache.wicket.ajax.AjaxRequestTarget;
+import org.apache.wicket.ajax.AjaxRequestTarget.IJavaScriptResponse;
+import org.apache.wicket.markup.html.internal.InlineEnclosure;
+import org.apache.wicket.markup.parser.filter.InlineEnclosureHandler;
+import org.apache.wicket.util.visit.IVisit;
+import org.apache.wicket.util.visit.IVisitor;
+
+/**
+ * This listener adds Enclosures to AjaxTarget, where the child controller of the said Enclosure is
+ * already added. This is a part of the fix to the problem:
+ *
+ * "Changing the visibility of a child component in Ajax callback method will not affect the entire
+ * enclosure but just the child component itself. This is because only the child component is added
+ * to the AjaxRequestTarget"
+ *
+ * When used with an "Inline" Enclosure, this problem is fixed.
+ *
+ * Syntax for inline enclosure:
+ *
+ * <tr wicket:enclosure="controllingChildId">
+ *
+ * In this example the tag used is tr, but any other tag could be used as well. The attribute
+ * "wicket:enclosure" is mandatory, and is used to recognise an inline enclosure. The value of the
+ * attribute, here "controllingChildId" can contain an id for the child (controller) element. If the
+ * said value is not given, the first element inside the enclosure will be used as a controller
+ * child. If there are no elements inside the enclosure, the parsing will fail.
+ *
+ *
+ * @see WebApplication
+ * @see InlineEnclosure
+ * @see InlineEnclosureHandler
+ * @see EnclosureResolver
+ *
+ * @author Joonas Hamalainen
+ */
+public class AjaxEnclosureListener implements AjaxRequestTarget.IListener
+{
+ /**
+ * Construct.
+ */
+ public AjaxEnclosureListener()
+ {
+ }
+
+ /**
+ * Try to find Enclosures that have their controllers added already, and add them to the target.
+ */
+ public void onBeforeRespond(final Map<String, Component> map, final AjaxRequestTarget target)
+ {
+ // We need to iterate over the map, but the map changes if we add an
+ // InlineEnclosure to the target. --> make a copy of the map and iterate that instead.
+ final List<Component> originalComponents = Collections.unmodifiableList(new ArrayList<Component>(
+ map.values()));
+
+ target.getPage().visitChildren(InlineEnclosure.class, new IVisitor<InlineEnclosure, Void>()
+ {
+ public void component(final InlineEnclosure enclosure, final IVisit<Void> visit)
+ {
+ for (Component component : originalComponents)
+ {
+ if (isControllerOfEnclosure(component, enclosure))
+ {
+ // update the visibility of the enclosure
+ enclosure.updateVisibility();
+
+ // add enclosure to Ajax target
+ target.add(enclosure);
+ }
+ }
+ }
+ });
+ }
+
+ /**
+ * Check if a given component is the controlling child of a given enclosure
+ *
+ * @param component
+ * @param enclosure
+ * @return true if the given component is the controlling child of the given InlineEnclosure
+ */
+ private boolean isControllerOfEnclosure(final Component component,
+ final InlineEnclosure enclosure)
+ {
+ return enclosure.getParent().get(enclosure.getChildId()) == component;
+ }
+
+ public void onAfterRespond(final Map<String, Component> map, final IJavaScriptResponse response)
+ {
+ }
+}
Modified: wicket/trunk/wicket-core/src/main/java/org/apache/wicket/protocol/http/WebApplication.java
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket-core/src/main/java/org/apache/wicket/protocol/http/WebApplication.java?rev=1090127&r1=1090126&r2=1090127&view=diff
==============================================================================
--- wicket/trunk/wicket-core/src/main/java/org/apache/wicket/protocol/http/WebApplication.java (original)
+++ wicket/trunk/wicket-core/src/main/java/org/apache/wicket/protocol/http/WebApplication.java Fri Apr 8 06:08:05 2011
@@ -522,6 +522,9 @@ public abstract class WebApplication ext
setPageRendererProvider(new WebPageRendererProvider());
setSessionStoreProvider(new WebSessionStoreProvider());
setAjaxRequestTargetProvider(new DefaultAjaxRequestTargetProvider());
+
+ getAjaxRequestTargetListeners().add(new AjaxEnclosureListener());
+
// Configure the app.
configure();
}
Added: wicket/trunk/wicket-core/src/test/java/org/apache/wicket/markup/html/internal/AjaxEnclosurePage_1.html
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket-core/src/test/java/org/apache/wicket/markup/html/internal/AjaxEnclosurePage_1.html?rev=1090127&view=auto
==============================================================================
--- wicket/trunk/wicket-core/src/test/java/org/apache/wicket/markup/html/internal/AjaxEnclosurePage_1.html (added)
+++ wicket/trunk/wicket-core/src/test/java/org/apache/wicket/markup/html/internal/AjaxEnclosurePage_1.html Fri Apr 8 06:08:05 2011
@@ -0,0 +1,22 @@
+<html xmlns:wicket>
+<body>
+
+<a href="#" wicket:id="toggleLabel1Link">Toggle label1 (and whole
+table) visibility</a>
+
+<a href="#" wicket:id="toggleLabel2Link">Toggle (only) label2
+visibility</a>
+
+<div wicket:enclosure="label1">
+ <table>
+ <tr>
+ <td><span wicket:id="label1">Test</span></td>
+ </tr>
+ <tr>
+ <td><span wicket:id="label2">Test</span></td>
+ </tr>
+ </table>
+</div>
+
+</body>
+</html>
Added: wicket/trunk/wicket-core/src/test/java/org/apache/wicket/markup/html/internal/AjaxEnclosurePage_1.java
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket-core/src/test/java/org/apache/wicket/markup/html/internal/AjaxEnclosurePage_1.java?rev=1090127&view=auto
==============================================================================
--- wicket/trunk/wicket-core/src/test/java/org/apache/wicket/markup/html/internal/AjaxEnclosurePage_1.java (added)
+++ wicket/trunk/wicket-core/src/test/java/org/apache/wicket/markup/html/internal/AjaxEnclosurePage_1.java Fri Apr 8 06:08:05 2011
@@ -0,0 +1,103 @@
+/*
+ * 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.ajax.AjaxRequestTarget;
+import org.apache.wicket.ajax.markup.html.AjaxLink;
+import org.apache.wicket.markup.html.WebPage;
+import org.apache.wicket.markup.html.basic.Label;
+
+
+/**
+ * Mock page for testing.
+ *
+ * @author Joonas Hamalainen
+ *
+ */
+public class AjaxEnclosurePage_1 extends WebPage
+{
+ private static final long serialVersionUID = 1L;
+
+ private final Label label1 = new Label("label1", "Test Label 1");
+ private final Label label2 = new Label("label2", "Test Label 2");
+ private final AjaxLink<Void> toggleLabel1Link;
+ private final AjaxLink<Void> toggleLabel2Link;
+
+ /**
+ * Construct.
+ */
+ public AjaxEnclosurePage_1()
+ {
+
+ toggleLabel1Link = new AjaxLink<Void>("toggleLabel1Link")
+ {
+ @Override
+ public void onClick(AjaxRequestTarget target)
+ {
+ label1.setVisible(!label1.isVisible());
+ target.addComponent(label1);
+ }
+
+ };
+ add(toggleLabel1Link);
+
+ toggleLabel2Link = new AjaxLink<Void>("toggleLabel2Link")
+ {
+ @Override
+ public void onClick(AjaxRequestTarget target)
+ {
+ label2.setVisible(!label2.isVisible());
+ target.addComponent(label2);
+ }
+
+ };
+ add(toggleLabel2Link);
+
+ label1.setOutputMarkupId(true);
+ label2.setOutputMarkupId(true);
+ label2.setOutputMarkupPlaceholderTag(true);
+ add(label1);
+ add(label2);
+ }
+
+
+ public static long getSerialversionuid()
+ {
+ return serialVersionUID;
+ }
+
+ public Label getLabel1()
+ {
+ return label1;
+ }
+
+ public Label getLabel2()
+ {
+ return label2;
+ }
+
+ public AjaxLink getToggleLabel1Link()
+ {
+ return toggleLabel1Link;
+ }
+
+ public AjaxLink<Void> getToggleLabel2Link()
+ {
+ return toggleLabel2Link;
+ }
+
+}
Added: wicket/trunk/wicket-core/src/test/java/org/apache/wicket/markup/html/internal/AjaxEnclosurePage_2.html
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket-core/src/test/java/org/apache/wicket/markup/html/internal/AjaxEnclosurePage_2.html?rev=1090127&view=auto
==============================================================================
--- wicket/trunk/wicket-core/src/test/java/org/apache/wicket/markup/html/internal/AjaxEnclosurePage_2.html (added)
+++ wicket/trunk/wicket-core/src/test/java/org/apache/wicket/markup/html/internal/AjaxEnclosurePage_2.html Fri Apr 8 06:08:05 2011
@@ -0,0 +1,31 @@
+<html xmlns:wicket>
+<body>
+
+<div>
+ <a href="#" wicket:id="toggleLabel1Link">Toggle label1</a>
+ <a href="#" wicket:id="toggleLabel2Link">Toggle label2</a>
+</div>
+
+<!-- nested inline enclosures with separate child depths and a container inside the first enclosure -->
+<div wicket:enclosure="container1:label1" style="border:2px solid red;">
+ <div wicket:id="container1">
+ <table>
+ <tr>
+ <td><span wicket:id="label1">Test</span></td>
+ </tr>
+ <tr>
+ <td>
+ <div wicket:enclosure="label2" style="border:2px solid blue;">
+ <div>
+ <span wicket:id="label2">Test</span>
+ <span wicket:id="enclosure2Marker">Test</span>
+ </div>
+ </div>
+ </td>
+ </tr>
+ </table>
+ </div>
+</div>
+
+</body>
+</html>
Added: wicket/trunk/wicket-core/src/test/java/org/apache/wicket/markup/html/internal/AjaxEnclosurePage_2.java
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket-core/src/test/java/org/apache/wicket/markup/html/internal/AjaxEnclosurePage_2.java?rev=1090127&view=auto
==============================================================================
--- wicket/trunk/wicket-core/src/test/java/org/apache/wicket/markup/html/internal/AjaxEnclosurePage_2.java (added)
+++ wicket/trunk/wicket-core/src/test/java/org/apache/wicket/markup/html/internal/AjaxEnclosurePage_2.java Fri Apr 8 06:08:05 2011
@@ -0,0 +1,116 @@
+/*
+ * 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.ajax.AjaxRequestTarget;
+import org.apache.wicket.ajax.markup.html.AjaxLink;
+import org.apache.wicket.markup.html.WebMarkupContainer;
+import org.apache.wicket.markup.html.WebPage;
+import org.apache.wicket.markup.html.basic.Label;
+
+
+/**
+ * Mock page for testing.
+ *
+ * @author Joonas Hamalainen
+ *
+ */
+public class AjaxEnclosurePage_2 extends WebPage
+{
+ private static final long serialVersionUID = 1L;
+
+ private final Label label1 = new Label("label1", "Test Label 1");
+ private final Label label2 = new Label("label2", "Test Label 2");
+ private final Label enclosure2Marker = new Label("enclosure2Marker", "enclosure2Marker Label");
+ private AjaxLink<Void> toggleLabel1Link;
+ private AjaxLink<Void> toggleLabel2Link;
+
+ private final WebMarkupContainer container1;
+
+ /**
+ * Construct.
+ */
+ public AjaxEnclosurePage_2()
+ {
+ addLinks();
+
+ container1 = new WebMarkupContainer("container1");
+ label1.setOutputMarkupId(true);
+ label2.setOutputMarkupId(true);
+ container1.add(label1);
+ container1.add(label2);
+ container1.add(enclosure2Marker);
+ add(container1);
+ }
+
+ private void addLinks()
+ {
+ toggleLabel1Link = new AjaxLink<Void>("toggleLabel1Link")
+ {
+ @Override
+ public void onClick(AjaxRequestTarget target)
+ {
+ label1.setVisible(!label1.isVisible());
+ target.addComponent(label1);
+ }
+
+ };
+ add(toggleLabel1Link);
+
+ toggleLabel2Link = new AjaxLink<Void>("toggleLabel2Link")
+ {
+ @Override
+ public void onClick(AjaxRequestTarget target)
+ {
+ label2.setVisible(!label2.isVisible());
+ target.addComponent(label2);
+ }
+ };
+ add(toggleLabel2Link);
+ }
+
+
+ public static long getSerialversionuid()
+ {
+ return serialVersionUID;
+ }
+
+ public Label getLabel1()
+ {
+ return label1;
+ }
+
+ public Label getLabel2()
+ {
+ return label2;
+ }
+
+ public AjaxLink<Void> getToggleLabel1Link()
+ {
+ return toggleLabel1Link;
+ }
+
+ public AjaxLink<Void> getToggleLabel2Link()
+ {
+ return toggleLabel2Link;
+ }
+
+ public Label getEnclosure2Marker()
+ {
+ return enclosure2Marker;
+ }
+}
Added: wicket/trunk/wicket-core/src/test/java/org/apache/wicket/markup/html/internal/AjaxEnclosurePage_3.html
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket-core/src/test/java/org/apache/wicket/markup/html/internal/AjaxEnclosurePage_3.html?rev=1090127&view=auto
==============================================================================
--- wicket/trunk/wicket-core/src/test/java/org/apache/wicket/markup/html/internal/AjaxEnclosurePage_3.html (added)
+++ wicket/trunk/wicket-core/src/test/java/org/apache/wicket/markup/html/internal/AjaxEnclosurePage_3.html Fri Apr 8 06:08:05 2011
@@ -0,0 +1,17 @@
+<html xmlns:wicket>
+<body>
+
+<a href="#" wicket:id="toggleLabel1Link">Toggle label1</a>
+
+<!-- Inline enclosure's controlling child is not explicitly stated,
+ it should use the only component inside.-->
+<div wicket:enclosure="">
+<table>
+ <tr>
+ <td><span wicket:id="label1">Test</span></td>
+ </tr>
+</table>
+</div>
+
+</body>
+</html>
Added: wicket/trunk/wicket-core/src/test/java/org/apache/wicket/markup/html/internal/AjaxEnclosurePage_3.java
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket-core/src/test/java/org/apache/wicket/markup/html/internal/AjaxEnclosurePage_3.java?rev=1090127&view=auto
==============================================================================
--- wicket/trunk/wicket-core/src/test/java/org/apache/wicket/markup/html/internal/AjaxEnclosurePage_3.java (added)
+++ wicket/trunk/wicket-core/src/test/java/org/apache/wicket/markup/html/internal/AjaxEnclosurePage_3.java Fri Apr 8 06:08:05 2011
@@ -0,0 +1,75 @@
+/*
+ * 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.ajax.AjaxRequestTarget;
+import org.apache.wicket.ajax.markup.html.AjaxLink;
+import org.apache.wicket.markup.html.WebPage;
+import org.apache.wicket.markup.html.basic.Label;
+
+
+/**
+ * Mock page for testing.
+ *
+ * @author Joonas Hamalainen
+ */
+public class AjaxEnclosurePage_3 extends WebPage
+{
+ private static final long serialVersionUID = 1L;
+
+ private final Label label1 = new Label("label1", "Test Label 1");
+ private AjaxLink<Void> toggleLabel1Link;
+
+ /**
+ * Construct.
+ */
+ public AjaxEnclosurePage_3()
+ {
+ addLinks();
+ label1.setOutputMarkupId(true);
+ add(label1);
+ }
+
+ private void addLinks()
+ {
+ toggleLabel1Link = new AjaxLink<Void>("toggleLabel1Link")
+ {
+ @Override
+ public void onClick(AjaxRequestTarget target)
+ {
+ label1.setVisible(!label1.isVisible());
+ target.addComponent(label1);
+ }
+ };
+ add(toggleLabel1Link);
+ }
+
+ public static long getSerialversionuid()
+ {
+ return serialVersionUID;
+ }
+
+ public Label getLabel1()
+ {
+ return label1;
+ }
+
+ public AjaxLink<Void> getToggleLabel1Link()
+ {
+ return toggleLabel1Link;
+ }
+}
Added: wicket/trunk/wicket-core/src/test/java/org/apache/wicket/markup/html/internal/AjaxEnclosureTest.java
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket-core/src/test/java/org/apache/wicket/markup/html/internal/AjaxEnclosureTest.java?rev=1090127&view=auto
==============================================================================
--- wicket/trunk/wicket-core/src/test/java/org/apache/wicket/markup/html/internal/AjaxEnclosureTest.java (added)
+++ wicket/trunk/wicket-core/src/test/java/org/apache/wicket/markup/html/internal/AjaxEnclosureTest.java Fri Apr 8 06:08:05 2011
@@ -0,0 +1,287 @@
+/*
+ * 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 java.util.regex.Pattern;
+
+import org.apache.wicket.Component;
+import org.apache.wicket.Page;
+import org.apache.wicket.WicketTestCase;
+import org.apache.wicket.markup.html.basic.Label;
+
+
+/**
+ * Simple test using the WicketTester
+ *
+ * @author Joonas Hamalainen
+ */
+public class AjaxEnclosureTest extends WicketTestCase
+{
+ private final String inlineEnclosureIdPrefix = "InlineEnclosure-";
+ private final String inlineEnclosureHiddenPattern = "<div id=\"" + inlineEnclosureIdPrefix +
+ "1\" style=\"display:none\"></div>";
+ private final String inlineEnclosureVisiblePattern = "<div id=\"" + inlineEnclosureIdPrefix +
+ "1\">";
+
+
+ /**
+ * Test toggling the controlling child inside the inline enclosure
+ */
+ public void testAjaxTogglingControllingChildShouldToggleInlineEnclosure()
+ {
+ {
+ // enclosure On
+ AjaxEnclosurePage_1 ajaxPage = (AjaxEnclosurePage_1)tester.startPage(AjaxEnclosurePage_1.class);
+ assertVisible(ajaxPage.getLabel1(), true);
+ assertVisible(ajaxPage.getLabel2(), true);
+ String doc = tester.getLastResponseAsString();
+ tester.clickLink(ajaxPage.getToggleLabel1Link().getPageRelativePath());
+ }
+ {
+ // enclosure Off
+ String doc = tester.getLastResponseAsString();
+ AjaxEnclosurePage_1 ajaxPage = (AjaxEnclosurePage_1)tester.getLastRenderedPage();
+ tester.assertContains(inlineEnclosureHiddenPattern);
+ assertInvisible(ajaxPage.getLabel1());
+ assertInvisible(ajaxPage.getLabel2());
+ tester.clickLink(ajaxPage.getToggleLabel1Link().getPageRelativePath());
+ }
+ {
+ // enclosure On
+ String doc = tester.getLastResponseAsString();
+ AjaxEnclosurePage_1 ajaxPage = (AjaxEnclosurePage_1)tester.getLastRenderedPage();
+ tester.assertContains(inlineEnclosureVisiblePattern);
+ assertVisible(ajaxPage.getLabel1(), true);
+ assertVisible(ajaxPage.getLabel2(), true);
+ tester.clickLink(ajaxPage.getToggleLabel1Link().getPageRelativePath());
+ }
+ {
+ // enclosure Off
+ String doc = tester.getLastResponseAsString();
+ AjaxEnclosurePage_1 ajaxPage = (AjaxEnclosurePage_1)tester.getLastRenderedPage();
+ tester.assertContains(inlineEnclosureHiddenPattern);
+ assertInvisible(ajaxPage.getLabel1());
+ assertInvisible(ajaxPage.getLabel2());
+ tester.clickLink(ajaxPage.getToggleLabel1Link().getPageRelativePath());
+ }
+ }
+
+ /**
+ * Test toggling a non-controlling child inside the inline enclosure
+ */
+ public void testAjaxTogglingNonControllingChildShouldNotToggleEnclosure()
+ {
+ final String enclosurePath = "InlineEnclosure-1";
+ {
+ // label 2 On
+ AjaxEnclosurePage_1 ajaxPage = (AjaxEnclosurePage_1)tester.startPage(AjaxEnclosurePage_1.class);
+ ensureEnclosureIsVisible(enclosurePath, ajaxPage);
+ assertVisible(ajaxPage.getLabel1(), true);
+ assertVisible(ajaxPage.getLabel2(), true);
+ tester.clickLink(ajaxPage.getToggleLabel2Link().getPageRelativePath());
+ }
+ {
+ // label 2 Off
+ AjaxEnclosurePage_1 ajaxPage = (AjaxEnclosurePage_1)tester.getLastRenderedPage();
+ ensureEnclosureIsVisible(enclosurePath, ajaxPage);
+ assertVisible(ajaxPage.getLabel1(), false);
+ assertInvisible(ajaxPage.getLabel2());
+ tester.clickLink(ajaxPage.getToggleLabel2Link().getPageRelativePath());
+ }
+ {
+ // label 2 On
+ AjaxEnclosurePage_1 ajaxPage = (AjaxEnclosurePage_1)tester.getLastRenderedPage();
+ ensureEnclosureIsVisible(enclosurePath, ajaxPage);
+ assertVisible(ajaxPage.getLabel1(), false);
+ assertVisible(ajaxPage.getLabel2(), false);
+ tester.clickLink(ajaxPage.getToggleLabel2Link().getPageRelativePath());
+ }
+ {
+ // label 2 Off
+ AjaxEnclosurePage_1 ajaxPage = (AjaxEnclosurePage_1)tester.getLastRenderedPage();
+ ensureEnclosureIsVisible(enclosurePath, ajaxPage);
+ assertVisible(ajaxPage.getLabel1(), false);
+ assertInvisible(ajaxPage.getLabel2());
+ tester.clickLink(ajaxPage.getToggleLabel2Link().getPageRelativePath());
+ }
+ }
+
+ /**
+ *
+ */
+ public void testNestedInlineEnclosuresShouldToggleNormally()
+ {
+ final String enclosure1Path = "InlineEnclosure-1";
+
+ {
+ // 1. test that enclosure1, enclosure2, label1, label2 are visible, click link1,
+ // hiding label1 and the whole enclosure
+ AjaxEnclosurePage_2 ajaxPage = (AjaxEnclosurePage_2)tester.startPage(AjaxEnclosurePage_2.class);
+ ensureEnclosureIsVisible(enclosure1Path, ajaxPage);
+ assertVisible(ajaxPage.getEnclosure2Marker(), true);
+ assertVisible(ajaxPage.getLabel1(), true);
+ assertVisible(ajaxPage.getLabel2(), true);
+ tester.clickLink(ajaxPage.getToggleLabel1Link().getPageRelativePath());
+ }
+ {
+ // 2. test that enclosure1, enclosure2, label1, label2 are INvisible, click link 1,
+ // bringing all back
+ AjaxEnclosurePage_2 ajaxPage = (AjaxEnclosurePage_2)tester.getLastRenderedPage();
+ ensureEnclosureIsInVisible(enclosure1Path, ajaxPage);
+ assertInvisible(ajaxPage.getEnclosure2Marker());
+ assertInvisible(ajaxPage.getLabel1());
+ assertInvisible(ajaxPage.getLabel2());
+ tester.clickLink(ajaxPage.getToggleLabel1Link().getPageRelativePath());
+ }
+ {
+ // 3. test that enclosure1, enclosure2, label1, label2 are visble, click link 2,
+ // hiding label 2 and enclosure 2
+ AjaxEnclosurePage_2 ajaxPage = (AjaxEnclosurePage_2)tester.getLastRenderedPage();
+ ensureEnclosureIsVisible(enclosure1Path, ajaxPage);
+ // ensureEnclosureIsVisible(enclosure2Path, ajaxPage);
+ assertVisible(ajaxPage.getEnclosure2Marker(), false);
+ assertVisible(ajaxPage.getLabel1(), false);
+ assertVisible(ajaxPage.getLabel2(), false);
+ tester.clickLink(ajaxPage.getToggleLabel2Link().getPageRelativePath());
+ }
+ {
+ // 4. test that enclosure1, label1 are visible and enclosure2, label2 INvisible.
+ // click link 2 again
+ AjaxEnclosurePage_2 ajaxPage = (AjaxEnclosurePage_2)tester.getLastRenderedPage();
+ ensureEnclosureIsVisible(enclosure1Path, ajaxPage);
+ assertVisible(ajaxPage.getLabel1(), false);
+ assertInvisible(ajaxPage.getEnclosure2Marker());
+ assertInvisible(ajaxPage.getLabel2());
+ tester.clickLink(ajaxPage.getToggleLabel2Link().getPageRelativePath());
+ }
+ {
+ // 3. test that enclosure1, enclosure2, label1, label2 are visble, Click link 1,
+ // hiding all
+ AjaxEnclosurePage_2 ajaxPage = (AjaxEnclosurePage_2)tester.getLastRenderedPage();
+ ensureEnclosureIsVisible(enclosure1Path, ajaxPage);
+ assertVisible(ajaxPage.getEnclosure2Marker(), false);
+ assertVisible(ajaxPage.getLabel1(), false);
+ assertVisible(ajaxPage.getLabel2(), false);
+ tester.clickLink(ajaxPage.getToggleLabel1Link().getPageRelativePath());
+ }
+ {
+ // 4. test that enclosure1, enclosure2 label1, label2 are invisible. click link 2
+ AjaxEnclosurePage_2 ajaxPage = (AjaxEnclosurePage_2)tester.getLastRenderedPage();
+ ensureEnclosureIsInVisible(enclosure1Path, ajaxPage);
+ assertInvisible(ajaxPage.getEnclosure2Marker());
+ assertInvisible(ajaxPage.getLabel1());
+ assertInvisible(ajaxPage.getLabel2());
+ tester.clickLink(ajaxPage.getToggleLabel2Link().getPageRelativePath());
+ }
+ {
+ // 5. test that enclosure1, enclosure2 label1, label2 are invisible. click link 1
+ AjaxEnclosurePage_2 ajaxPage = (AjaxEnclosurePage_2)tester.getLastRenderedPage();
+ ensureEnclosureIsInVisible(enclosure1Path, ajaxPage);
+ assertInvisible(ajaxPage.getEnclosure2Marker());
+ assertInvisible(ajaxPage.getLabel1());
+ assertInvisible(ajaxPage.getLabel2());
+ tester.clickLink(ajaxPage.getToggleLabel1Link().getPageRelativePath());
+ }
+ {
+ // 6. test that enclosure1, label1 are visible, and enclosure2, label2 invisible
+ // (because of step 4)
+ AjaxEnclosurePage_2 ajaxPage = (AjaxEnclosurePage_2)tester.getLastRenderedPage();
+ ensureEnclosureIsVisible(enclosure1Path, ajaxPage);
+ assertInvisible(ajaxPage.getEnclosure2Marker());
+ assertVisible(ajaxPage.getLabel1(), false);
+ assertInvisible(ajaxPage.getLabel2());
+ tester.clickLink(ajaxPage.getToggleLabel1Link().getPageRelativePath());
+ }
+
+ }
+
+ /**
+ *
+ */
+ public void testControllingChildShouldDefaultToTheSingleComponentInsideEnclosure()
+ {
+ final String enclosurePath = "InlineEnclosure-1";
+
+ {
+ // enclosure On
+ AjaxEnclosurePage_3 ajaxPage = (AjaxEnclosurePage_3)tester.startPage(AjaxEnclosurePage_3.class);
+ assertVisible(ajaxPage.getLabel1(), true);
+ ensureEnclosureIsVisible(enclosurePath, ajaxPage);
+ tester.clickLink(ajaxPage.getToggleLabel1Link().getPageRelativePath());
+ }
+ {
+ // enclosure Off
+ AjaxEnclosurePage_3 ajaxPage = (AjaxEnclosurePage_3)tester.getLastRenderedPage();
+ tester.assertContains(inlineEnclosureHiddenPattern);
+ assertInvisible(ajaxPage.getLabel1());
+ ensureEnclosureIsInVisible(enclosurePath, ajaxPage);
+ tester.clickLink(ajaxPage.getToggleLabel1Link().getPageRelativePath());
+ }
+ {
+ // enclosure On
+ AjaxEnclosurePage_3 ajaxPage = (AjaxEnclosurePage_3)tester.getLastRenderedPage();
+ tester.assertContains(inlineEnclosureVisiblePattern);
+ assertVisible(ajaxPage.getLabel1(), true);
+ ensureEnclosureIsVisible(enclosurePath, ajaxPage);
+ tester.clickLink(ajaxPage.getToggleLabel1Link().getPageRelativePath());
+ }
+ {
+ // enclosure Off
+ AjaxEnclosurePage_3 ajaxPage = (AjaxEnclosurePage_3)tester.getLastRenderedPage();
+ tester.assertContains(inlineEnclosureHiddenPattern);
+ assertInvisible(ajaxPage.getLabel1());
+ ensureEnclosureIsInVisible(enclosurePath, ajaxPage);
+ tester.clickLink(ajaxPage.getToggleLabel1Link().getPageRelativePath());
+ }
+ }
+
+ private void ensureEnclosureIsVisible(final String enclosurePath, Page ajaxPage)
+ {
+ Component enclosure = ajaxPage.get(enclosurePath);
+ assertTrue("Is not visible", enclosure.determineVisibility());
+ }
+
+ private void ensureEnclosureIsInVisible(final String enclosurePath, Page ajaxPage)
+ {
+ Component enclosure = ajaxPage.get(enclosurePath);
+ if (enclosure != null)
+ {
+ assertFalse("Is visible", enclosure.determineVisibility());
+ }
+ }
+
+ protected void assertVisible(Label label, boolean checkAlsoMarkup)
+ {
+ tester.assertVisible(label.getPageRelativePath());
+ if (checkAlsoMarkup)
+ {
+ tester.assertContains(Pattern.quote(label.getInnermostModel().getObject().toString()));
+ }
+ }
+
+ protected void assertInvisible(Label label)
+ {
+ // tester.assertInvisible(label.getPageRelativePath());
+ assertDoesNotContain(Pattern.quote(label.getInnermostModel().getObject().toString()));
+ }
+
+ protected void assertDoesNotContain(String string)
+ {
+ assertFalse("Should not contain: " + string,
+ tester.getLastResponseAsString().contains(string));
+ }
+}
\ No newline at end of file
Added: wicket/trunk/wicket-core/src/test/java/org/apache/wicket/markup/html/internal/FullReloadPage.html
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket-core/src/test/java/org/apache/wicket/markup/html/internal/FullReloadPage.html?rev=1090127&view=auto
==============================================================================
--- wicket/trunk/wicket-core/src/test/java/org/apache/wicket/markup/html/internal/FullReloadPage.html (added)
+++ wicket/trunk/wicket-core/src/test/java/org/apache/wicket/markup/html/internal/FullReloadPage.html Fri Apr 8 06:08:05 2011
@@ -0,0 +1,29 @@
+<!DOCTYPE html>
+<html>
+<head>
+</head>
+<body>
+
+<table border="1" cellpadding="1" cellspacing="1">
+ <tr>
+ <th>Header row</th>
+ </tr>
+ <tr>
+ <td><a wicket:id="link">Toggle</a></td>
+ </tr>
+ <wicket:enclosure child="toggleable">
+ <tr bgcolor="red">
+ <td><input wicket:id="toggleable" type="button"
+ style="border: 1px solid black; background: lightblue;"
+ value="This button (and red border) should appear and disappear by pressing toggle" />
+ (Also this)</td>
+ </tr>
+ </wicket:enclosure>
+</table>
+<br clear="all" />
+<br clear="all" />
+Here toggle is possible: no problem, because whole page is repainted (no
+ajax).
+
+</body>
+</html>
\ No newline at end of file
Added: wicket/trunk/wicket-core/src/test/java/org/apache/wicket/markup/html/internal/FullReloadPage.java
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket-core/src/test/java/org/apache/wicket/markup/html/internal/FullReloadPage.java?rev=1090127&view=auto
==============================================================================
--- wicket/trunk/wicket-core/src/test/java/org/apache/wicket/markup/html/internal/FullReloadPage.java (added)
+++ wicket/trunk/wicket-core/src/test/java/org/apache/wicket/markup/html/internal/FullReloadPage.java Fri Apr 8 06:08:05 2011
@@ -0,0 +1,65 @@
+/*
+ * 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.WebMarkupContainer;
+import org.apache.wicket.markup.html.WebPage;
+import org.apache.wicket.markup.html.link.Link;
+
+
+/**
+ */
+public class FullReloadPage extends WebPage
+{
+ /** */
+ private static final long serialVersionUID = 1L;
+ private final WebMarkupContainer toggleable;
+ private final Link<Void> link;
+
+ /**
+ *
+ */
+ @SuppressWarnings("serial")
+ public FullReloadPage()
+ {
+ add(toggleable = new WebMarkupContainer("toggleable"));
+ add(link = new Link<Void>("link")
+ {
+ @Override
+ public void onClick()
+ {
+ toggleable.setVisible(!toggleable.isVisible());
+ }
+ });
+ }
+
+ /**
+ * @return the toggleable element
+ */
+ public WebMarkupContainer getToggleable()
+ {
+ return toggleable;
+ }
+
+ /**
+ * @return the toggle link
+ */
+ public Link<Void> getLink()
+ {
+ return link;
+ }
+}
\ No newline at end of file
Added: wicket/trunk/wicket-core/src/test/java/org/apache/wicket/markup/html/internal/InlineEnclosureAjaxPage.html
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket-core/src/test/java/org/apache/wicket/markup/html/internal/InlineEnclosureAjaxPage.html?rev=1090127&view=auto
==============================================================================
--- wicket/trunk/wicket-core/src/test/java/org/apache/wicket/markup/html/internal/InlineEnclosureAjaxPage.html (added)
+++ wicket/trunk/wicket-core/src/test/java/org/apache/wicket/markup/html/internal/InlineEnclosureAjaxPage.html Fri Apr 8 06:08:05 2011
@@ -0,0 +1,22 @@
+<!DOCTYPE html>
+<html>
+<head>
+</head>
+<body>
+<table border="1" cellpadding="1" cellspacing="1">
+ <tr>
+ <th>Header row</th>
+ </tr>
+ <tr>
+ <td><a wicket:id="link">Toggle</a></td>
+ </tr>
+ <tr wicket:enclosure="toggleable" bgcolor="red">
+ <td><input wicket:id="toggleable" type="button"
+ value="This button (and red border) should appear and disappear by pressing toggle"
+ style="border: 1px solid black; background: lightblue;" /> Also this
+ part should toggle</td>
+ </tr>
+</table>
+
+</body>
+</html>
\ No newline at end of file
Added: wicket/trunk/wicket-core/src/test/java/org/apache/wicket/markup/html/internal/InlineEnclosureAjaxPage.java
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket-core/src/test/java/org/apache/wicket/markup/html/internal/InlineEnclosureAjaxPage.java?rev=1090127&view=auto
==============================================================================
--- wicket/trunk/wicket-core/src/test/java/org/apache/wicket/markup/html/internal/InlineEnclosureAjaxPage.java (added)
+++ wicket/trunk/wicket-core/src/test/java/org/apache/wicket/markup/html/internal/InlineEnclosureAjaxPage.java Fri Apr 8 06:08:05 2011
@@ -0,0 +1,76 @@
+/*
+ * 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.ajax.AjaxRequestTarget;
+import org.apache.wicket.ajax.markup.html.AjaxLink;
+import org.apache.wicket.markup.html.WebMarkupContainer;
+import org.apache.wicket.markup.html.WebPage;
+
+/**
+ */
+public class InlineEnclosureAjaxPage extends WebPage
+{
+ /** */
+ private static final long serialVersionUID = 1L;
+ private final WebMarkupContainer toggleable;
+ private final AjaxLink<Void> link;
+
+ /**
+ *
+ */
+ @SuppressWarnings("serial")
+ public InlineEnclosureAjaxPage()
+ {
+ {
+ add((toggleable = new WebMarkupContainer("toggleable")).setOutputMarkupPlaceholderTag(true));
+ add(link = new AjaxLink<Void>("link")
+ {
+ @Override
+ public void onClick(AjaxRequestTarget target)
+ {
+ toggleable.setVisible(!toggleable.isVisible());
+ ajaxRepaintOnlyToggleableComponentsContainer(target);
+ }
+ });
+ }
+ }
+
+ /**
+ * @param target
+ */
+ private void ajaxRepaintOnlyToggleableComponentsContainer(AjaxRequestTarget target)
+ {
+ target.addComponent(toggleable);
+ }
+
+ /**
+ * @return the toggleable element
+ */
+ public WebMarkupContainer getToggleable()
+ {
+ return toggleable;
+ }
+
+ /**
+ * @return toggle link
+ */
+ public AjaxLink<Void> getLink()
+ {
+ return link;
+ }
+}
\ No newline at end of file
Added: wicket/trunk/wicket-core/src/test/java/org/apache/wicket/markup/html/internal/InlineEnclosurePageExpectedResult_1.html
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket-core/src/test/java/org/apache/wicket/markup/html/internal/InlineEnclosurePageExpectedResult_1.html?rev=1090127&view=auto
==============================================================================
--- wicket/trunk/wicket-core/src/test/java/org/apache/wicket/markup/html/internal/InlineEnclosurePageExpectedResult_1.html (added)
+++ wicket/trunk/wicket-core/src/test/java/org/apache/wicket/markup/html/internal/InlineEnclosurePageExpectedResult_1.html Fri Apr 8 06:08:05 2011
@@ -0,0 +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"></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="customInlineEnclosureId"><span>Test Label 10</span>
+</div>
+
+
+</body>
+</html>
Added: wicket/trunk/wicket-core/src/test/java/org/apache/wicket/markup/html/internal/InlineEnclosurePageExpectedResult_2.html
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket-core/src/test/java/org/apache/wicket/markup/html/internal/InlineEnclosurePageExpectedResult_2.html?rev=1090127&view=auto
==============================================================================
--- wicket/trunk/wicket-core/src/test/java/org/apache/wicket/markup/html/internal/InlineEnclosurePageExpectedResult_2.html (added)
+++ wicket/trunk/wicket-core/src/test/java/org/apache/wicket/markup/html/internal/InlineEnclosurePageExpectedResult_2.html Fri Apr 8 06:08:05 2011
@@ -0,0 +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>
Added: wicket/trunk/wicket-core/src/test/java/org/apache/wicket/markup/html/internal/InlineEnclosurePage_1.html
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket-core/src/test/java/org/apache/wicket/markup/html/internal/InlineEnclosurePage_1.html?rev=1090127&view=auto
==============================================================================
--- wicket/trunk/wicket-core/src/test/java/org/apache/wicket/markup/html/internal/InlineEnclosurePage_1.html (added)
+++ wicket/trunk/wicket-core/src/test/java/org/apache/wicket/markup/html/internal/InlineEnclosurePage_1.html Fri Apr 8 06:08:05 2011
@@ -0,0 +1,50 @@
+<html xmlns:wicket>
+<body>
+
+<span wicket:enclosure=""> <span wicket:id="label1">Test</span> </span>
+
+<div wicket:enclosure="label2">
+ <table>
+ <tr>
+ <td><span wicket:id="label2">Test</span></td>
+ </tr>
+ </table>
+</div>
+
+<span wicket:enclosure=""> <span wicket:id="label3">Test</span> </span>
+
+<div wicket:enclosure="label6">
+ <table>
+ <tr>
+ <td><span wicket:id="label4">Test</span></td>
+ </tr>
+ </table>
+ <table>
+ <tr>
+ <td><span wicket:id="label5">Test</span></td>
+ </tr>
+ </table>
+ <table>
+ <tr>
+ <td><span wicket:id="label6">Test</span></td>
+ </tr>
+ </table>
+ <table>
+ <tr>
+ <td><span wicket:id="label7">Test</span></td>
+ </tr>
+ </table>
+</div>
+
+<div wicket:enclosure="container:label8"><span
+ wicket:id="container"> <span wicket:id="label8">Test</span> </span></div>
+
+<div wicket:enclosure=""><span wicket:id="label9">Test</span></div>
+
+<div wicket:id="customInlineEnclosureId"
+ wicket:enclosure="label10"><span wicket:id="label10">Test</span>
+</div>
+
+
+</body>
+</html>
Added: wicket/trunk/wicket-core/src/test/java/org/apache/wicket/markup/html/internal/InlineEnclosurePage_1.java
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket-core/src/test/java/org/apache/wicket/markup/html/internal/InlineEnclosurePage_1.java?rev=1090127&view=auto
==============================================================================
--- wicket/trunk/wicket-core/src/test/java/org/apache/wicket/markup/html/internal/InlineEnclosurePage_1.java (added)
+++ wicket/trunk/wicket-core/src/test/java/org/apache/wicket/markup/html/internal/InlineEnclosurePage_1.java Fri Apr 8 06:08:05 2011
@@ -0,0 +1,72 @@
+/*
+ * 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.WebMarkupContainer;
+import org.apache.wicket.markup.html.WebPage;
+import org.apache.wicket.markup.html.basic.Label;
+
+
+/**
+ * Mock page for testing.
+ *
+ * @author Joonas Hamalainen
+ *
+ */
+public class InlineEnclosurePage_1 extends WebPage
+{
+ private static final long serialVersionUID = 1L;
+
+ private final Label label1 = new Label("label1", "Test Label 1");
+ private final Label label2 = new Label("label2", "Test Label 2");
+ private final Label label3 = new Label("label3", "Test Label 3");
+ private final Label label4 = new Label("label4", "Test Label 4");
+ private final Label label5 = new Label("label5", "Test Label 5");
+ private final Label label6 = new Label("label6", "Test Label 6");
+ private final Label label7 = new Label("label7", "Test Label 7");
+ private final Label label8 = new Label("label8", "Test Label 8");
+ private final Label label9 = new Label("label9", "Test Label 9");
+ private final Label label10 = new Label("label10", "Test Label 10");
+
+ /**
+ * Construct.
+ */
+ public InlineEnclosurePage_1()
+ {
+ add(label1);
+ add(label2);
+ add(label3.setVisible(false));
+ add(label4);
+ add(label5);
+ add(label6);
+ add(label7);
+
+ WebMarkupContainer container = new WebMarkupContainer("container");
+ add(container);
+ container.add(label8);
+
+ add(label9);
+ add(label10);
+ }
+
+ public static long getSerialversionuid()
+ {
+ return serialVersionUID;
+ }
+
+
+}
Added: wicket/trunk/wicket-core/src/test/java/org/apache/wicket/markup/html/internal/InlineEnclosurePage_2.html
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket-core/src/test/java/org/apache/wicket/markup/html/internal/InlineEnclosurePage_2.html?rev=1090127&view=auto
==============================================================================
--- wicket/trunk/wicket-core/src/test/java/org/apache/wicket/markup/html/internal/InlineEnclosurePage_2.html (added)
+++ wicket/trunk/wicket-core/src/test/java/org/apache/wicket/markup/html/internal/InlineEnclosurePage_2.html Fri Apr 8 06:08:05 2011
@@ -0,0 +1,106 @@
+<html xmlns:wicket>
+<body>
+
+<!-- nested inline enclosures with separate child depths. -->
+<div wicket:enclosure="label1"><span wicket:id="label1">Test</span>
+ <div wicket:enclosure="label2">
+ <table>
+ <tr>
+ <td><span wicket:id="label2">Test</span></td>
+ </tr>
+ </table>
+ </div>
+</div>
+
+<!-- nested inline enclosures with same child depth. -->
+<div wicket:enclosure="label3">
+ <div wicket:enclosure="label4">
+ <span wicket:id="label3">Test</span>
+ <span wicket:id="label4">Test</span>
+ </div>
+</div>
+
+<!-- enclosure tag nested inside inline enclosure with separate child depths. -->
+<div wicket:enclosure="label5"> <span wicket:id="label5">Test</span>
+ <wicket:enclosure child="label6">
+ <table>
+ <tr>
+ <td>
+ <span wicket:id="label6">Test</span>
+ </td>
+ </tr>
+ </table>
+ </wicket:enclosure>
+</div>
+
+<!-- enclosure tag nested inside inline enclosure with same child depth. -->
+<div wicket:enclosure="label7">
+ <wicket:enclosure child="label8">
+ <table>
+ <tr>
+ <td>
+ <span wicket:id="label7">Test</span>
+ <span wicket:id="label8">Test</span>
+ </td>
+ </tr>
+ </table>
+ </wicket:enclosure>
+</div>
+
+<!-- inline enclosure nested inside enclosure tag with separate child depths. -->
+<wicket:enclosure child="label9">
+ <div wicket:enclosure="label10"> <span wicket:id="label9">Test</span>
+ <table>
+ <tr>
+ <td><span wicket:id="label10">Test</span></td>
+ </tr>
+ </table>
+ </div>
+</wicket:enclosure>
+
+<!-- inline enclosure nested inside enclosure tag with same child depth. -->
+<div wicket:enclosure="label11">
+ <wicket:enclosure child="label12">
+ <table>
+ <tr>
+ <td>
+ <span wicket:id="label11">Test</span>
+ <span wicket:id="label12">Test</span>
+ </td>
+ </tr>
+ </table>
+ </wicket:enclosure>
+</div>
+
+<!-- inline enclosure nested inside enclosure tag with same child depth inside a wicket container. -->
+<wicket:enclosure child="container:label14">
+ <div wicket:enclosure="container:label13">
+ <div wicket:id="container">
+ <table>
+ <tr>
+ <td>
+ <span wicket:id="label13">Test</span>
+ <span wicket:id="label14">Test</span>
+ </td>
+ </tr>
+ </table>
+ </div>
+ </div>
+</wicket:enclosure>
+
+
+<!-- nested inline enclosures without explicitly determining children -->
+<div wicket:enclosure="">
+ <div wicket:enclosure="">
+ <table>
+ <tr>
+ <td>
+ <span wicket:id="label15">Test</span>
+ </td>
+ </tr>
+ </table>
+ </div>
+</div>
+
+</body>
+</html>
Added: wicket/trunk/wicket-core/src/test/java/org/apache/wicket/markup/html/internal/InlineEnclosurePage_2.java
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket-core/src/test/java/org/apache/wicket/markup/html/internal/InlineEnclosurePage_2.java?rev=1090127&view=auto
==============================================================================
--- wicket/trunk/wicket-core/src/test/java/org/apache/wicket/markup/html/internal/InlineEnclosurePage_2.java (added)
+++ wicket/trunk/wicket-core/src/test/java/org/apache/wicket/markup/html/internal/InlineEnclosurePage_2.java Fri Apr 8 06:08:05 2011
@@ -0,0 +1,81 @@
+/*
+ * 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.WebMarkupContainer;
+import org.apache.wicket.markup.html.WebPage;
+import org.apache.wicket.markup.html.basic.Label;
+
+
+/**
+ * Mock page for testing.
+ *
+ * @author Joonas Hamalainen
+ *
+ */
+public class InlineEnclosurePage_2 extends WebPage
+{
+ private static final long serialVersionUID = 1L;
+
+ private final Label label1 = new Label("label1", "Test Label 1");
+ private final Label label2 = new Label("label2", "Test Label 2");
+ private final Label label3 = new Label("label3", "Test Label 3");
+ private final Label label4 = new Label("label4", "Test Label 4");
+ private final Label label5 = new Label("label5", "Test Label 5");
+ private final Label label6 = new Label("label6", "Test Label 6");
+ private final Label label7 = new Label("label7", "Test Label 7");
+ private final Label label8 = new Label("label8", "Test Label 8");
+ private final Label label9 = new Label("label9", "Test Label 9");
+ private final Label label10 = new Label("label10", "Test Label 10");
+ private final Label label11 = new Label("label11", "Test Label 11");
+ private final Label label12 = new Label("label12", "Test Label 12");
+ private final Label label13 = new Label("label13", "Test Label 13");
+ private final Label label14 = new Label("label14", "Test Label 14");
+ private final Label label15 = new Label("label15", "Test Label 15");
+
+ /**
+ * Construct.
+ */
+ public InlineEnclosurePage_2()
+ {
+ add(label1);
+ add(label2);
+ add(label3);
+ add(label4);
+ add(label5);
+ add(label6);
+ add(label7);
+ add(label8);
+ add(label9);
+ add(label10);
+ add(label11);
+ add(label12);
+
+ WebMarkupContainer container = new WebMarkupContainer("container");
+ add(container);
+ container.add(label13);
+ container.add(label14);
+
+ add(label15);
+ }
+
+ public static long getSerialversionuid()
+ {
+ return serialVersionUID;
+ }
+
+}
Added: wicket/trunk/wicket-core/src/test/java/org/apache/wicket/markup/html/internal/InlineEnclosurePanelPage.html
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket-core/src/test/java/org/apache/wicket/markup/html/internal/InlineEnclosurePanelPage.html?rev=1090127&view=auto
==============================================================================
--- wicket/trunk/wicket-core/src/test/java/org/apache/wicket/markup/html/internal/InlineEnclosurePanelPage.html (added)
+++ wicket/trunk/wicket-core/src/test/java/org/apache/wicket/markup/html/internal/InlineEnclosurePanelPage.html Fri Apr 8 06:08:05 2011
@@ -0,0 +1,9 @@
+<html xmlns:wicket>
+<body>
+ <div wicket:enclosure="testPanel1:label1">
+ <div>
+ <div wicket:id="testPanel1"></div>
+ </div>
+ </div>
+</body>
+</html>
Added: wicket/trunk/wicket-core/src/test/java/org/apache/wicket/markup/html/internal/InlineEnclosurePanelPage.java
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket-core/src/test/java/org/apache/wicket/markup/html/internal/InlineEnclosurePanelPage.java?rev=1090127&view=auto
==============================================================================
--- wicket/trunk/wicket-core/src/test/java/org/apache/wicket/markup/html/internal/InlineEnclosurePanelPage.java (added)
+++ wicket/trunk/wicket-core/src/test/java/org/apache/wicket/markup/html/internal/InlineEnclosurePanelPage.java Fri Apr 8 06:08:05 2011
@@ -0,0 +1,39 @@
+/*
+ * 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;
+
+
+/**
+ * Mock page for testing (see WICKET-3422).
+ *
+ * @author Joonas Hamalainen
+ */
+public class InlineEnclosurePanelPage extends WebPage
+{
+ private static final long serialVersionUID = 1L;
+
+ /**
+ * Construct.
+ */
+ public InlineEnclosurePanelPage()
+ {
+ add(new SimplePanel2("testPanel1"));
+ }
+
+}
Added: wicket/trunk/wicket-core/src/test/java/org/apache/wicket/markup/html/internal/InlineEnclosurePanelPageExpectedResult.html
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket-core/src/test/java/org/apache/wicket/markup/html/internal/InlineEnclosurePanelPageExpectedResult.html?rev=1090127&view=auto
==============================================================================
--- wicket/trunk/wicket-core/src/test/java/org/apache/wicket/markup/html/internal/InlineEnclosurePanelPageExpectedResult.html (added)
+++ wicket/trunk/wicket-core/src/test/java/org/apache/wicket/markup/html/internal/InlineEnclosurePanelPageExpectedResult.html Fri Apr 8 06:08:05 2011
@@ -0,0 +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>