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/03/12 17:28:59 UTC
svn commit: r1080946 [1/2] - in /wicket/branches/wicket-1.4.x/wicket/src:
main/java/org/apache/wicket/ main/java/org/apache/wicket/markup/
main/java/org/apache/wicket/markup/html/internal/
main/java/org/apache/wicket/markup/parser/filter/ main/java/org...
Author: jdonnerstag
Date: Sat Mar 12 16:28:57 2011
New Revision: 1080946
URL: http://svn.apache.org/viewvc?rev=1080946&view=rev
Log:
fixed WICKET-3422: Simplified visibility control of Enclosures in Ajax requests
Issue: WICKET-3422
Added:
wicket/branches/wicket-1.4.x/wicket/src/main/java/org/apache/wicket/markup/html/internal/InlineEnclosure.java
wicket/branches/wicket-1.4.x/wicket/src/main/java/org/apache/wicket/markup/parser/filter/InlineEnclosureHandler.java
wicket/branches/wicket-1.4.x/wicket/src/main/java/org/apache/wicket/protocol/http/AjaxEnclosureListener.java
wicket/branches/wicket-1.4.x/wicket/src/test/java/org/apache/wicket/markup/html/internal/AjaxEnclosurePage_1.html
wicket/branches/wicket-1.4.x/wicket/src/test/java/org/apache/wicket/markup/html/internal/AjaxEnclosurePage_1.java
wicket/branches/wicket-1.4.x/wicket/src/test/java/org/apache/wicket/markup/html/internal/AjaxEnclosurePage_2.html
wicket/branches/wicket-1.4.x/wicket/src/test/java/org/apache/wicket/markup/html/internal/AjaxEnclosurePage_2.java
wicket/branches/wicket-1.4.x/wicket/src/test/java/org/apache/wicket/markup/html/internal/AjaxEnclosurePage_3.html
wicket/branches/wicket-1.4.x/wicket/src/test/java/org/apache/wicket/markup/html/internal/AjaxEnclosurePage_3.java
wicket/branches/wicket-1.4.x/wicket/src/test/java/org/apache/wicket/markup/html/internal/AjaxEnclosureTest.java
wicket/branches/wicket-1.4.x/wicket/src/test/java/org/apache/wicket/markup/html/internal/FullReloadPage.html
wicket/branches/wicket-1.4.x/wicket/src/test/java/org/apache/wicket/markup/html/internal/FullReloadPage.java
wicket/branches/wicket-1.4.x/wicket/src/test/java/org/apache/wicket/markup/html/internal/InlineEnclosureAjaxPage.html
wicket/branches/wicket-1.4.x/wicket/src/test/java/org/apache/wicket/markup/html/internal/InlineEnclosureAjaxPage.java
wicket/branches/wicket-1.4.x/wicket/src/test/java/org/apache/wicket/markup/html/internal/InlineEnclosurePageExpectedResult_1.html
wicket/branches/wicket-1.4.x/wicket/src/test/java/org/apache/wicket/markup/html/internal/InlineEnclosurePageExpectedResult_2.html
wicket/branches/wicket-1.4.x/wicket/src/test/java/org/apache/wicket/markup/html/internal/InlineEnclosurePage_1.html
wicket/branches/wicket-1.4.x/wicket/src/test/java/org/apache/wicket/markup/html/internal/InlineEnclosurePage_1.java
wicket/branches/wicket-1.4.x/wicket/src/test/java/org/apache/wicket/markup/html/internal/InlineEnclosurePage_2.html
wicket/branches/wicket-1.4.x/wicket/src/test/java/org/apache/wicket/markup/html/internal/InlineEnclosurePage_2.java
wicket/branches/wicket-1.4.x/wicket/src/test/java/org/apache/wicket/markup/html/internal/InlineEnclosurePanelPage.html
wicket/branches/wicket-1.4.x/wicket/src/test/java/org/apache/wicket/markup/html/internal/InlineEnclosurePanelPage.java
wicket/branches/wicket-1.4.x/wicket/src/test/java/org/apache/wicket/markup/html/internal/InlineEnclosurePanelPageExpectedResult.html
wicket/branches/wicket-1.4.x/wicket/src/test/java/org/apache/wicket/markup/html/internal/InlineEnclosureTest.java
wicket/branches/wicket-1.4.x/wicket/src/test/java/org/apache/wicket/markup/html/internal/InlineEnclosureWithAdditionalAjaxTargetPage.html
wicket/branches/wicket-1.4.x/wicket/src/test/java/org/apache/wicket/markup/html/internal/InlineEnclosureWithAdditionalAjaxTargetPage.java
wicket/branches/wicket-1.4.x/wicket/src/test/java/org/apache/wicket/markup/html/internal/SimplePanel2.html
wicket/branches/wicket-1.4.x/wicket/src/test/java/org/apache/wicket/markup/html/internal/SimplePanel2.java
wicket/branches/wicket-1.4.x/wicket/src/test/java/org/apache/wicket/markup/html/internal/TogglePageTests.java
wicket/branches/wicket-1.4.x/wicket/src/test/java/org/apache/wicket/markup/html/internal/TraditionalEnclosureAjaxPage.html
wicket/branches/wicket-1.4.x/wicket/src/test/java/org/apache/wicket/markup/html/internal/TraditionalEnclosureAjaxPage.java
Modified:
wicket/branches/wicket-1.4.x/wicket/src/main/java/org/apache/wicket/MarkupContainer.java
wicket/branches/wicket-1.4.x/wicket/src/main/java/org/apache/wicket/markup/DefaultMarkupCacheKeyProvider.java
wicket/branches/wicket-1.4.x/wicket/src/main/java/org/apache/wicket/markup/MarkupParser.java
wicket/branches/wicket-1.4.x/wicket/src/main/java/org/apache/wicket/markup/html/internal/Enclosure.java
wicket/branches/wicket-1.4.x/wicket/src/main/java/org/apache/wicket/markup/resolver/EnclosureResolver.java
wicket/branches/wicket-1.4.x/wicket/src/main/java/org/apache/wicket/protocol/http/WebApplication.java
Modified: wicket/branches/wicket-1.4.x/wicket/src/main/java/org/apache/wicket/MarkupContainer.java
URL: http://svn.apache.org/viewvc/wicket/branches/wicket-1.4.x/wicket/src/main/java/org/apache/wicket/MarkupContainer.java?rev=1080946&r1=1080945&r2=1080946&view=diff
==============================================================================
--- wicket/branches/wicket-1.4.x/wicket/src/main/java/org/apache/wicket/MarkupContainer.java (original)
+++ wicket/branches/wicket-1.4.x/wicket/src/main/java/org/apache/wicket/MarkupContainer.java Sat Mar 12 16:28:57 2011
@@ -29,6 +29,7 @@ import org.apache.wicket.markup.MarkupEx
import org.apache.wicket.markup.MarkupNotFoundException;
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.resolver.ComponentResolvers;
import org.apache.wicket.model.IComponentInheritedModel;
import org.apache.wicket.model.IModel;
@@ -79,7 +80,6 @@ import org.slf4j.LoggerFactory;
*
* @see MarkupStream
* @author Jonathan Locke
- *
*/
public abstract class MarkupContainer extends Component
{
@@ -1680,7 +1680,10 @@ 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);
}
@@ -1789,7 +1792,7 @@ 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/branches/wicket-1.4.x/wicket/src/main/java/org/apache/wicket/markup/DefaultMarkupCacheKeyProvider.java
URL: http://svn.apache.org/viewvc/wicket/branches/wicket-1.4.x/wicket/src/main/java/org/apache/wicket/markup/DefaultMarkupCacheKeyProvider.java?rev=1080946&r1=1080945&r2=1080946&view=diff
==============================================================================
--- wicket/branches/wicket-1.4.x/wicket/src/main/java/org/apache/wicket/markup/DefaultMarkupCacheKeyProvider.java (original)
+++ wicket/branches/wicket-1.4.x/wicket/src/main/java/org/apache/wicket/markup/DefaultMarkupCacheKeyProvider.java Sat Mar 12 16:28:57 2011
@@ -81,6 +81,10 @@ public class DefaultMarkupCacheKeyProvid
buffer.append(style);
}
+ // Without this dot, the file extension is not separated from
+ // the file name, causing many unit tests to fail
+ buffer.append(".");
+
buffer.append(markupType);
return buffer.toString();
}
Modified: wicket/branches/wicket-1.4.x/wicket/src/main/java/org/apache/wicket/markup/MarkupParser.java
URL: http://svn.apache.org/viewvc/wicket/branches/wicket-1.4.x/wicket/src/main/java/org/apache/wicket/markup/MarkupParser.java?rev=1080946&r1=1080945&r2=1080946&view=diff
==============================================================================
--- wicket/branches/wicket-1.4.x/wicket/src/main/java/org/apache/wicket/markup/MarkupParser.java (original)
+++ wicket/branches/wicket-1.4.x/wicket/src/main/java/org/apache/wicket/markup/MarkupParser.java Sat Mar 12 16:28:57 2011
@@ -31,6 +31,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.WicketLinkTagHandler;
@@ -184,6 +185,7 @@ public class MarkupParser
appendMarkupFilter(new OpenCloseTagExpander());
appendMarkupFilter(new RelativePathPrefixHandler());
appendMarkupFilter(new EnclosureHandler());
+ appendMarkupFilter(new InlineEnclosureHandler());
}
/**
Modified: wicket/branches/wicket-1.4.x/wicket/src/main/java/org/apache/wicket/markup/html/internal/Enclosure.java
URL: http://svn.apache.org/viewvc/wicket/branches/wicket-1.4.x/wicket/src/main/java/org/apache/wicket/markup/html/internal/Enclosure.java?rev=1080946&r1=1080945&r2=1080946&view=diff
==============================================================================
--- wicket/branches/wicket-1.4.x/wicket/src/main/java/org/apache/wicket/markup/html/internal/Enclosure.java (original)
+++ wicket/branches/wicket-1.4.x/wicket/src/main/java/org/apache/wicket/markup/html/internal/Enclosure.java Sat Mar 12 16:28:57 2011
@@ -100,7 +100,6 @@ public class Enclosure extends WebMarkup
{
super(id);
-
if (childId == null)
{
throw new MarkupException(
@@ -125,7 +124,7 @@ public class Enclosure extends WebMarkup
*
* @return enclosure's parent markup container
*/
- private MarkupContainer getEnclosureParent()
+ protected MarkupContainer getEnclosureParent()
{
MarkupContainer parent = getParent();
while (parent != null)
@@ -192,13 +191,14 @@ public class Enclosure extends WebMarkup
}
}
- private void warnAboutFormComponentInsideEnclosure(FormComponent fc)
+ private void warnAboutFormComponentInsideEnclosure(FormComponent<?> fc)
{
log.warn(
"Found a form component {}/{} inside an enclosure. Form components do not work well inside wicket:enclosure tags, use EnclosureContainer instead",
fc.getClass().getSimpleName(), fc.getPageRelativePath());
}
+ @SuppressWarnings("rawtypes")
private void warnAboutFormComponentsInsideEnclosure(final MarkupContainer container,
final MarkupStream markupStream, ComponentTag enclosureOpenTag)
{
Added: wicket/branches/wicket-1.4.x/wicket/src/main/java/org/apache/wicket/markup/html/internal/InlineEnclosure.java
URL: http://svn.apache.org/viewvc/wicket/branches/wicket-1.4.x/wicket/src/main/java/org/apache/wicket/markup/html/internal/InlineEnclosure.java?rev=1080946&view=auto
==============================================================================
--- wicket/branches/wicket-1.4.x/wicket/src/main/java/org/apache/wicket/markup/html/internal/InlineEnclosure.java (added)
+++ wicket/branches/wicket-1.4.x/wicket/src/main/java/org/apache/wicket/markup/html/internal/InlineEnclosure.java Sat Mar 12 16:28:57 2011
@@ -0,0 +1,181 @@
+/*
+ * 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.ArrayList;
+import java.util.List;
+
+import org.apache.wicket.Component;
+import org.apache.wicket.MarkupContainer;
+import org.apache.wicket.markup.ComponentTag;
+import org.apache.wicket.markup.MarkupException;
+import org.apache.wicket.markup.MarkupStream;
+import org.apache.wicket.markup.parser.filter.InlineEnclosureHandler;
+import org.apache.wicket.markup.resolver.ComponentResolvers;
+import org.apache.wicket.markup.resolver.EnclosureResolver;
+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
+ */
+public class InlineEnclosure extends Enclosure
+{
+ private static final long serialVersionUID = 1L;
+
+ private static final Logger log = LoggerFactory.getLogger(InlineEnclosure.class);
+
+ /** Id of the child component that will control visibility of the enclosure */
+ private final CharSequence childId;
+
+ /**
+ * This transient child list is filled only at onComponentTagBody. Therefore it is not
+ * necessarily accurate at any given time.
+ **/
+ private transient List<Component> children = null;
+
+ /**
+ * Construct.
+ *
+ * @param id
+ * @param childId
+ * @param isInlineEnclosure
+ */
+ public InlineEnclosure(final String id, final String childId)
+ {
+ super(id, childId);
+
+ if (childId == null)
+ {
+ throw new MarkupException(
+ "You most likely forgot to register the EnclosureHandler with the MarkupParserFactory");
+ }
+
+ this.childId = childId;
+ }
+
+ @Override
+ protected void onAfterRenderChildren()
+ {
+ if (children == null)
+ {
+ log.warn("Child list not yet generated.");
+ }
+ else
+ {
+ for (Component child : children)
+ {
+ child.afterRender();
+ }
+ }
+
+ super.onAfterRenderChildren();
+ }
+
+ /**
+ * Return the controlling child component
+ *
+ * @return the child component.
+ */
+ private Component getChildComponent()
+ {
+ // enclosure's parent container
+ final MarkupContainer container = getEnclosureParent();
+ Component child = container.get(childId.toString());
+ return child;
+ }
+
+ /**
+ * Update the visibility of this In-line enclosure with that of the controlling child.
+ *
+ * @return the new visibility setting.
+ */
+ public boolean updateVisibility()
+ {
+ Component child = getChildComponent();
+ boolean visible = child.isVisible();
+ setVisible(visible);
+ return visible;
+ }
+
+ @Override
+ protected void onComponentTagBody(final MarkupStream markupStream, ComponentTag enclosureOpenTag)
+ {
+ enumerateChildren(markupStream, enclosureOpenTag);
+
+ super.onComponentTagBody(markupStream, enclosureOpenTag);
+ }
+
+ private void enumerateChildren(final MarkupStream markupStream, ComponentTag enclosureOpenTag)
+ {
+ final MarkupContainer container = getEnclosureParent();
+ // update child list
+ children = new ArrayList<Component>();
+
+ DirectChildTagIterator it = new DirectChildTagIterator(markupStream, enclosureOpenTag);
+ while (it.hasNext())
+ {
+ final ComponentTag tag = it.next();
+ if (tag.isAutoComponentTag() == false)
+ {
+ Component child = container.get(tag.getId());
+ if (child == null)
+ {
+ // because the resolvers can auto-add and therefore immediately render the
+ // component we have to buffer the output since we do not yet know the
+ // visibility of the enclosure
+ CharSequence buffer = new ResponseBufferZone(getRequestCycle(), markupStream)
+ {
+ @Override
+ protected void executeInsideBufferedZone()
+ {
+ final int ind = markupStream.findComponentIndex(tag.getPath(),
+ tag.getId());
+ markupStream.setCurrentIndex(ind);
+ ComponentResolvers.resolve(getApplication(), container, markupStream,
+ tag);
+ }
+ }.execute();
+ child = container.get(tag.getId());
+ }
+ children.add(child);
+ }
+ }
+ it.rewind();
+ }
+
+ /**
+ * Returns the controlling child's Id
+ *
+ * @return the id of the child component
+ */
+ public String getChildId()
+ {
+ return childId.toString();
+ }
+}
Added: wicket/branches/wicket-1.4.x/wicket/src/main/java/org/apache/wicket/markup/parser/filter/InlineEnclosureHandler.java
URL: http://svn.apache.org/viewvc/wicket/branches/wicket-1.4.x/wicket/src/main/java/org/apache/wicket/markup/parser/filter/InlineEnclosureHandler.java?rev=1080946&view=auto
==============================================================================
--- wicket/branches/wicket-1.4.x/wicket/src/main/java/org/apache/wicket/markup/parser/filter/InlineEnclosureHandler.java (added)
+++ wicket/branches/wicket-1.4.x/wicket/src/main/java/org/apache/wicket/markup/parser/filter/InlineEnclosureHandler.java Sat Mar 12 16:28:57 2011
@@ -0,0 +1,163 @@
+/*
+ * 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.Session;
+import org.apache.wicket.markup.ComponentTag;
+import org.apache.wicket.markup.MarkupElement;
+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.EnclosureResolver;
+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
+ */
+public final class InlineEnclosureHandler extends AbstractMarkupFilter
+{
+ private final static String INLINE_ENCLOSURE_ID_PREFIX = "inlineEnclosure-";
+ private final static String INLINE_ENCLOSURE_ATTRIBUTE_NAME = "wicket:enclosure";
+
+ private Stack<ComponentTag> enclosures;
+
+ /**
+ * Construct.
+ */
+ public InlineEnclosureHandler()
+ {
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public final MarkupElement nextTag() throws ParseException
+ {
+ // Get the next tag from the next MarkupFilter in the chain.
+ // If null, no more tags are available
+ final ComponentTag tag = nextComponentTag();
+ if ((tag == null) || (tag instanceof WicketTag))
+ {
+ return tag;
+ }
+
+ // Has wicket:enclosure attribute?
+ String enclosureAttr = getInlineEnclosureAttribute(tag);
+ if (enclosureAttr != null)
+ {
+ if (tag.isOpen())
+ {
+ String htmlId = tag.getAttribute("id");
+ if ((tag.getId() != null) && !Strings.isEmpty(htmlId) &&
+ !htmlId.equals(tag.getId()))
+ {
+ throw new ParseException(
+ "Make sure the 'id' and 'wicket:id' should be the same if both are used. 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))
+ {
+ String id = INLINE_ENCLOSURE_ID_PREFIX + Session.get().nextSequenceValue();
+ tag.setId(id);
+ }
+ else
+ {
+ tag.setId(htmlId);
+ }
+
+ tag.setAutoComponentTag(true);
+ tag.setModified(true);
+ }
+
+ tag.getAttributes().put("id", tag.getId());
+
+ 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());
+ }
+ }
+ else if ((enclosures != null) && (enclosures.size() > 0))
+ {
+ 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);
+ }
+}
Modified: wicket/branches/wicket-1.4.x/wicket/src/main/java/org/apache/wicket/markup/resolver/EnclosureResolver.java
URL: http://svn.apache.org/viewvc/wicket/branches/wicket-1.4.x/wicket/src/main/java/org/apache/wicket/markup/resolver/EnclosureResolver.java?rev=1080946&r1=1080945&r2=1080946&view=diff
==============================================================================
--- wicket/branches/wicket-1.4.x/wicket/src/main/java/org/apache/wicket/markup/resolver/EnclosureResolver.java (original)
+++ wicket/branches/wicket-1.4.x/wicket/src/main/java/org/apache/wicket/markup/resolver/EnclosureResolver.java Sat Mar 12 16:28:57 2011
@@ -21,7 +21,9 @@ import org.apache.wicket.markup.Componen
import org.apache.wicket.markup.MarkupStream;
import org.apache.wicket.markup.WicketTag;
import org.apache.wicket.markup.html.internal.Enclosure;
+import org.apache.wicket.markup.html.internal.InlineEnclosure;
import org.apache.wicket.markup.parser.filter.EnclosureHandler;
+import org.apache.wicket.markup.parser.filter.InlineEnclosureHandler;
/**
* This is a tag resolver which automatically adds a Enclosure container for each
@@ -36,18 +38,17 @@ public class EnclosureResolver implement
{
private static final long serialVersionUID = 1L;
- /**
- *
- * @see org.apache.wicket.markup.resolver.IComponentResolver#resolve(org.apache.wicket.MarkupContainer,
- * org.apache.wicket.markup.MarkupStream, org.apache.wicket.markup.ComponentTag)
- */
public boolean resolve(final MarkupContainer container, final MarkupStream markupStream,
final ComponentTag tag)
{
- if ((tag instanceof WicketTag) && ((WicketTag)tag).isEnclosureTag())
+ boolean isEnclosureTag = (tag instanceof WicketTag) && ((WicketTag)tag).isEnclosureTag();
+ String inlineEnclosureChildId = InlineEnclosureHandler.getInlineEnclosureAttribute(tag);
+
+ if (isEnclosureTag)
{
- CharSequence wicketId = tag.getString("wicket:id");
String id = null;
+
+ CharSequence wicketId = tag.getString("wicket:id");
if (wicketId != null)
{
id = wicketId.toString();
@@ -56,15 +57,23 @@ public class EnclosureResolver implement
{
id = "enclosure-" + container.getPage().getAutoIndex();
}
- final Enclosure enclosure = new Enclosure(id,
- tag.getString(EnclosureHandler.CHILD_ATTRIBUTE));
+
+ CharSequence childId = tag.getString(EnclosureHandler.CHILD_ATTRIBUTE);
+ Enclosure enclosure = new Enclosure(id, childId);
+
+ container.autoAdd(enclosure, markupStream);
+
+ return true;
+ }
+ else if (inlineEnclosureChildId != null)
+ {
+ Enclosure enclosure = new InlineEnclosure(tag.getId(), inlineEnclosureChildId);
+
container.autoAdd(enclosure, markupStream);
- // Yes, we handled the tag
return true;
}
- // We were not able to handle the tag
return false;
}
}
\ No newline at end of file
Added: wicket/branches/wicket-1.4.x/wicket/src/main/java/org/apache/wicket/protocol/http/AjaxEnclosureListener.java
URL: http://svn.apache.org/viewvc/wicket/branches/wicket-1.4.x/wicket/src/main/java/org/apache/wicket/protocol/http/AjaxEnclosureListener.java?rev=1080946&view=auto
==============================================================================
--- wicket/branches/wicket-1.4.x/wicket/src/main/java/org/apache/wicket/protocol/http/AjaxEnclosureListener.java (added)
+++ wicket/branches/wicket-1.4.x/wicket/src/main/java/org/apache/wicket/protocol/http/AjaxEnclosureListener.java Sat Mar 12 16:28:57 2011
@@ -0,0 +1,117 @@
+/*
+ * 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.Component.IVisitor;
+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.markup.resolver.EnclosureResolver;
+
+/**
+ * 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
+{
+ /**
+ * 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)
+ {
+ // TODO Instead of adding the listener, it would nicer if AjaxRequestTarget would call a
+ // component.onComponentAdded() method which adds the enclosure to the target as well.
+ // Having to explicitly add the listener is awkward bsides that it now gets added to all
+ // ARTs.
+
+ // 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>()
+ {
+ public Object component(final InlineEnclosure enclosure)
+ {
+ for (Component component : originalComponents)
+ {
+ if (isControllerOfEnclosure(component, enclosure))
+ {
+ // ensure that the Enclosure is ready for ajax updates
+ enclosure.setOutputMarkupId(true);
+ enclosure.setOutputMarkupPlaceholderTag(true);
+ enclosure.setMarkupId(enclosure.getId());
+
+ // update the visibility of the enclosure
+ enclosure.updateVisibility();
+
+ // add enclosure to Ajax target
+ target.addComponent(enclosure);
+ }
+ }
+ return IVisitor.CONTINUE_TRAVERSAL;
+ }
+ });
+ }
+
+ /**
+ * 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/branches/wicket-1.4.x/wicket/src/main/java/org/apache/wicket/protocol/http/WebApplication.java
URL: http://svn.apache.org/viewvc/wicket/branches/wicket-1.4.x/wicket/src/main/java/org/apache/wicket/protocol/http/WebApplication.java?rev=1080946&r1=1080945&r2=1080946&view=diff
==============================================================================
--- wicket/branches/wicket-1.4.x/wicket/src/main/java/org/apache/wicket/protocol/http/WebApplication.java (original)
+++ wicket/branches/wicket-1.4.x/wicket/src/main/java/org/apache/wicket/protocol/http/WebApplication.java Sat Mar 12 16:28:57 2011
@@ -698,7 +698,9 @@ public abstract class WebApplication ext
*/
public AjaxRequestTarget newAjaxRequestTarget(final Page page)
{
- return new AjaxRequestTarget(page);
+ AjaxRequestTarget target = new AjaxRequestTarget(page);
+ target.addListener(new AjaxEnclosureListener());
+ return target;
}
/**
Added: wicket/branches/wicket-1.4.x/wicket/src/test/java/org/apache/wicket/markup/html/internal/AjaxEnclosurePage_1.html
URL: http://svn.apache.org/viewvc/wicket/branches/wicket-1.4.x/wicket/src/test/java/org/apache/wicket/markup/html/internal/AjaxEnclosurePage_1.html?rev=1080946&view=auto
==============================================================================
--- wicket/branches/wicket-1.4.x/wicket/src/test/java/org/apache/wicket/markup/html/internal/AjaxEnclosurePage_1.html (added)
+++ wicket/branches/wicket-1.4.x/wicket/src/test/java/org/apache/wicket/markup/html/internal/AjaxEnclosurePage_1.html Sat Mar 12 16:28:57 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/branches/wicket-1.4.x/wicket/src/test/java/org/apache/wicket/markup/html/internal/AjaxEnclosurePage_1.java
URL: http://svn.apache.org/viewvc/wicket/branches/wicket-1.4.x/wicket/src/test/java/org/apache/wicket/markup/html/internal/AjaxEnclosurePage_1.java?rev=1080946&view=auto
==============================================================================
--- wicket/branches/wicket-1.4.x/wicket/src/test/java/org/apache/wicket/markup/html/internal/AjaxEnclosurePage_1.java (added)
+++ wicket/branches/wicket-1.4.x/wicket/src/test/java/org/apache/wicket/markup/html/internal/AjaxEnclosurePage_1.java Sat Mar 12 16:28:57 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/branches/wicket-1.4.x/wicket/src/test/java/org/apache/wicket/markup/html/internal/AjaxEnclosurePage_2.html
URL: http://svn.apache.org/viewvc/wicket/branches/wicket-1.4.x/wicket/src/test/java/org/apache/wicket/markup/html/internal/AjaxEnclosurePage_2.html?rev=1080946&view=auto
==============================================================================
--- wicket/branches/wicket-1.4.x/wicket/src/test/java/org/apache/wicket/markup/html/internal/AjaxEnclosurePage_2.html (added)
+++ wicket/branches/wicket-1.4.x/wicket/src/test/java/org/apache/wicket/markup/html/internal/AjaxEnclosurePage_2.html Sat Mar 12 16:28:57 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/branches/wicket-1.4.x/wicket/src/test/java/org/apache/wicket/markup/html/internal/AjaxEnclosurePage_2.java
URL: http://svn.apache.org/viewvc/wicket/branches/wicket-1.4.x/wicket/src/test/java/org/apache/wicket/markup/html/internal/AjaxEnclosurePage_2.java?rev=1080946&view=auto
==============================================================================
--- wicket/branches/wicket-1.4.x/wicket/src/test/java/org/apache/wicket/markup/html/internal/AjaxEnclosurePage_2.java (added)
+++ wicket/branches/wicket-1.4.x/wicket/src/test/java/org/apache/wicket/markup/html/internal/AjaxEnclosurePage_2.java Sat Mar 12 16:28:57 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/branches/wicket-1.4.x/wicket/src/test/java/org/apache/wicket/markup/html/internal/AjaxEnclosurePage_3.html
URL: http://svn.apache.org/viewvc/wicket/branches/wicket-1.4.x/wicket/src/test/java/org/apache/wicket/markup/html/internal/AjaxEnclosurePage_3.html?rev=1080946&view=auto
==============================================================================
--- wicket/branches/wicket-1.4.x/wicket/src/test/java/org/apache/wicket/markup/html/internal/AjaxEnclosurePage_3.html (added)
+++ wicket/branches/wicket-1.4.x/wicket/src/test/java/org/apache/wicket/markup/html/internal/AjaxEnclosurePage_3.html Sat Mar 12 16:28:57 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/branches/wicket-1.4.x/wicket/src/test/java/org/apache/wicket/markup/html/internal/AjaxEnclosurePage_3.java
URL: http://svn.apache.org/viewvc/wicket/branches/wicket-1.4.x/wicket/src/test/java/org/apache/wicket/markup/html/internal/AjaxEnclosurePage_3.java?rev=1080946&view=auto
==============================================================================
--- wicket/branches/wicket-1.4.x/wicket/src/test/java/org/apache/wicket/markup/html/internal/AjaxEnclosurePage_3.java (added)
+++ wicket/branches/wicket-1.4.x/wicket/src/test/java/org/apache/wicket/markup/html/internal/AjaxEnclosurePage_3.java Sat Mar 12 16:28:57 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/branches/wicket-1.4.x/wicket/src/test/java/org/apache/wicket/markup/html/internal/AjaxEnclosureTest.java
URL: http://svn.apache.org/viewvc/wicket/branches/wicket-1.4.x/wicket/src/test/java/org/apache/wicket/markup/html/internal/AjaxEnclosureTest.java?rev=1080946&view=auto
==============================================================================
--- wicket/branches/wicket-1.4.x/wicket/src/test/java/org/apache/wicket/markup/html/internal/AjaxEnclosureTest.java (added)
+++ wicket/branches/wicket-1.4.x/wicket/src/test/java/org/apache/wicket/markup/html/internal/AjaxEnclosureTest.java Sat Mar 12 16:28:57 2011
@@ -0,0 +1,288 @@
+/*
+ * 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.getServletResponse().getDocument();
+ tester.clickLink(ajaxPage.getToggleLabel1Link().getPageRelativePath());
+ }
+ {
+ // enclosure Off
+ String doc = tester.getServletResponse().getDocument();
+ 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.getServletResponse().getDocument();
+ 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.getServletResponse().getDocument();
+ 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.getServletResponse()
+ .getDocument()
+ .contains(string));
+ }
+}
\ No newline at end of file
Added: wicket/branches/wicket-1.4.x/wicket/src/test/java/org/apache/wicket/markup/html/internal/FullReloadPage.html
URL: http://svn.apache.org/viewvc/wicket/branches/wicket-1.4.x/wicket/src/test/java/org/apache/wicket/markup/html/internal/FullReloadPage.html?rev=1080946&view=auto
==============================================================================
--- wicket/branches/wicket-1.4.x/wicket/src/test/java/org/apache/wicket/markup/html/internal/FullReloadPage.html (added)
+++ wicket/branches/wicket-1.4.x/wicket/src/test/java/org/apache/wicket/markup/html/internal/FullReloadPage.html Sat Mar 12 16:28:57 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/branches/wicket-1.4.x/wicket/src/test/java/org/apache/wicket/markup/html/internal/FullReloadPage.java
URL: http://svn.apache.org/viewvc/wicket/branches/wicket-1.4.x/wicket/src/test/java/org/apache/wicket/markup/html/internal/FullReloadPage.java?rev=1080946&view=auto
==============================================================================
--- wicket/branches/wicket-1.4.x/wicket/src/test/java/org/apache/wicket/markup/html/internal/FullReloadPage.java (added)
+++ wicket/branches/wicket-1.4.x/wicket/src/test/java/org/apache/wicket/markup/html/internal/FullReloadPage.java Sat Mar 12 16:28:57 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/branches/wicket-1.4.x/wicket/src/test/java/org/apache/wicket/markup/html/internal/InlineEnclosureAjaxPage.html
URL: http://svn.apache.org/viewvc/wicket/branches/wicket-1.4.x/wicket/src/test/java/org/apache/wicket/markup/html/internal/InlineEnclosureAjaxPage.html?rev=1080946&view=auto
==============================================================================
--- wicket/branches/wicket-1.4.x/wicket/src/test/java/org/apache/wicket/markup/html/internal/InlineEnclosureAjaxPage.html (added)
+++ wicket/branches/wicket-1.4.x/wicket/src/test/java/org/apache/wicket/markup/html/internal/InlineEnclosureAjaxPage.html Sat Mar 12 16:28:57 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/branches/wicket-1.4.x/wicket/src/test/java/org/apache/wicket/markup/html/internal/InlineEnclosureAjaxPage.java
URL: http://svn.apache.org/viewvc/wicket/branches/wicket-1.4.x/wicket/src/test/java/org/apache/wicket/markup/html/internal/InlineEnclosureAjaxPage.java?rev=1080946&view=auto
==============================================================================
--- wicket/branches/wicket-1.4.x/wicket/src/test/java/org/apache/wicket/markup/html/internal/InlineEnclosureAjaxPage.java (added)
+++ wicket/branches/wicket-1.4.x/wicket/src/test/java/org/apache/wicket/markup/html/internal/InlineEnclosureAjaxPage.java Sat Mar 12 16:28:57 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/branches/wicket-1.4.x/wicket/src/test/java/org/apache/wicket/markup/html/internal/InlineEnclosurePageExpectedResult_1.html
URL: http://svn.apache.org/viewvc/wicket/branches/wicket-1.4.x/wicket/src/test/java/org/apache/wicket/markup/html/internal/InlineEnclosurePageExpectedResult_1.html?rev=1080946&view=auto
==============================================================================
--- wicket/branches/wicket-1.4.x/wicket/src/test/java/org/apache/wicket/markup/html/internal/InlineEnclosurePageExpectedResult_1.html (added)
+++ wicket/branches/wicket-1.4.x/wicket/src/test/java/org/apache/wicket/markup/html/internal/InlineEnclosurePageExpectedResult_1.html Sat Mar 12 16:28:57 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/branches/wicket-1.4.x/wicket/src/test/java/org/apache/wicket/markup/html/internal/InlineEnclosurePageExpectedResult_2.html
URL: http://svn.apache.org/viewvc/wicket/branches/wicket-1.4.x/wicket/src/test/java/org/apache/wicket/markup/html/internal/InlineEnclosurePageExpectedResult_2.html?rev=1080946&view=auto
==============================================================================
--- wicket/branches/wicket-1.4.x/wicket/src/test/java/org/apache/wicket/markup/html/internal/InlineEnclosurePageExpectedResult_2.html (added)
+++ wicket/branches/wicket-1.4.x/wicket/src/test/java/org/apache/wicket/markup/html/internal/InlineEnclosurePageExpectedResult_2.html Sat Mar 12 16:28:57 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-6">
+
+ <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-7"> <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-8">
+
+ <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-9">
+ <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-10">
+ <div id="inlineEnclosure-11">
+ <table>
+ <tr>
+ <td>
+ <span>Test Label 15</span>
+ </td>
+ </tr>
+ </table>
+ </div>
+</div>
+
+</body>
+</html>
Added: wicket/branches/wicket-1.4.x/wicket/src/test/java/org/apache/wicket/markup/html/internal/InlineEnclosurePage_1.html
URL: http://svn.apache.org/viewvc/wicket/branches/wicket-1.4.x/wicket/src/test/java/org/apache/wicket/markup/html/internal/InlineEnclosurePage_1.html?rev=1080946&view=auto
==============================================================================
--- wicket/branches/wicket-1.4.x/wicket/src/test/java/org/apache/wicket/markup/html/internal/InlineEnclosurePage_1.html (added)
+++ wicket/branches/wicket-1.4.x/wicket/src/test/java/org/apache/wicket/markup/html/internal/InlineEnclosurePage_1.html Sat Mar 12 16:28:57 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/branches/wicket-1.4.x/wicket/src/test/java/org/apache/wicket/markup/html/internal/InlineEnclosurePage_1.java
URL: http://svn.apache.org/viewvc/wicket/branches/wicket-1.4.x/wicket/src/test/java/org/apache/wicket/markup/html/internal/InlineEnclosurePage_1.java?rev=1080946&view=auto
==============================================================================
--- wicket/branches/wicket-1.4.x/wicket/src/test/java/org/apache/wicket/markup/html/internal/InlineEnclosurePage_1.java (added)
+++ wicket/branches/wicket-1.4.x/wicket/src/test/java/org/apache/wicket/markup/html/internal/InlineEnclosurePage_1.java Sat Mar 12 16:28:57 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/branches/wicket-1.4.x/wicket/src/test/java/org/apache/wicket/markup/html/internal/InlineEnclosurePage_2.html
URL: http://svn.apache.org/viewvc/wicket/branches/wicket-1.4.x/wicket/src/test/java/org/apache/wicket/markup/html/internal/InlineEnclosurePage_2.html?rev=1080946&view=auto
==============================================================================
--- wicket/branches/wicket-1.4.x/wicket/src/test/java/org/apache/wicket/markup/html/internal/InlineEnclosurePage_2.html (added)
+++ wicket/branches/wicket-1.4.x/wicket/src/test/java/org/apache/wicket/markup/html/internal/InlineEnclosurePage_2.html Sat Mar 12 16:28:57 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/branches/wicket-1.4.x/wicket/src/test/java/org/apache/wicket/markup/html/internal/InlineEnclosurePage_2.java
URL: http://svn.apache.org/viewvc/wicket/branches/wicket-1.4.x/wicket/src/test/java/org/apache/wicket/markup/html/internal/InlineEnclosurePage_2.java?rev=1080946&view=auto
==============================================================================
--- wicket/branches/wicket-1.4.x/wicket/src/test/java/org/apache/wicket/markup/html/internal/InlineEnclosurePage_2.java (added)
+++ wicket/branches/wicket-1.4.x/wicket/src/test/java/org/apache/wicket/markup/html/internal/InlineEnclosurePage_2.java Sat Mar 12 16:28:57 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/branches/wicket-1.4.x/wicket/src/test/java/org/apache/wicket/markup/html/internal/InlineEnclosurePanelPage.html
URL: http://svn.apache.org/viewvc/wicket/branches/wicket-1.4.x/wicket/src/test/java/org/apache/wicket/markup/html/internal/InlineEnclosurePanelPage.html?rev=1080946&view=auto
==============================================================================
--- wicket/branches/wicket-1.4.x/wicket/src/test/java/org/apache/wicket/markup/html/internal/InlineEnclosurePanelPage.html (added)
+++ wicket/branches/wicket-1.4.x/wicket/src/test/java/org/apache/wicket/markup/html/internal/InlineEnclosurePanelPage.html Sat Mar 12 16:28:57 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/branches/wicket-1.4.x/wicket/src/test/java/org/apache/wicket/markup/html/internal/InlineEnclosurePanelPage.java
URL: http://svn.apache.org/viewvc/wicket/branches/wicket-1.4.x/wicket/src/test/java/org/apache/wicket/markup/html/internal/InlineEnclosurePanelPage.java?rev=1080946&view=auto
==============================================================================
--- wicket/branches/wicket-1.4.x/wicket/src/test/java/org/apache/wicket/markup/html/internal/InlineEnclosurePanelPage.java (added)
+++ wicket/branches/wicket-1.4.x/wicket/src/test/java/org/apache/wicket/markup/html/internal/InlineEnclosurePanelPage.java Sat Mar 12 16:28:57 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/branches/wicket-1.4.x/wicket/src/test/java/org/apache/wicket/markup/html/internal/InlineEnclosurePanelPageExpectedResult.html
URL: http://svn.apache.org/viewvc/wicket/branches/wicket-1.4.x/wicket/src/test/java/org/apache/wicket/markup/html/internal/InlineEnclosurePanelPageExpectedResult.html?rev=1080946&view=auto
==============================================================================
--- wicket/branches/wicket-1.4.x/wicket/src/test/java/org/apache/wicket/markup/html/internal/InlineEnclosurePanelPageExpectedResult.html (added)
+++ wicket/branches/wicket-1.4.x/wicket/src/test/java/org/apache/wicket/markup/html/internal/InlineEnclosurePanelPageExpectedResult.html Sat Mar 12 16:28:57 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>
Added: wicket/branches/wicket-1.4.x/wicket/src/test/java/org/apache/wicket/markup/html/internal/InlineEnclosureTest.java
URL: http://svn.apache.org/viewvc/wicket/branches/wicket-1.4.x/wicket/src/test/java/org/apache/wicket/markup/html/internal/InlineEnclosureTest.java?rev=1080946&view=auto
==============================================================================
--- wicket/branches/wicket-1.4.x/wicket/src/test/java/org/apache/wicket/markup/html/internal/InlineEnclosureTest.java (added)
+++ wicket/branches/wicket-1.4.x/wicket/src/test/java/org/apache/wicket/markup/html/internal/InlineEnclosureTest.java Sat Mar 12 16:28:57 2011
@@ -0,0 +1,78 @@
+/*
+ * 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.Page;
+import org.apache.wicket.WicketTestCase;
+import org.apache.wicket.protocol.http.WebApplication;
+import org.apache.wicket.util.tester.WicketTester;
+
+
+/**
+ * Simple test using the WicketTester
+ *
+ * @author Joonas Hamalainen
+ */
+public class InlineEnclosureTest extends WicketTestCase
+{
+
+ /**
+ * @throws Exception
+ */
+ public void testInlineEnclosurePage_1() throws Exception
+ {
+ executeTest(InlineEnclosurePage_1.class, "InlineEnclosurePageExpectedResult_1.html");
+ }
+
+ /**
+ * @throws Exception
+ */
+ public void testInlineEnclosurePage_2() throws Exception
+ {
+ executeTest(InlineEnclosurePage_2.class, "InlineEnclosurePageExpectedResult_2.html");
+ }
+
+ /**
+ * @throws Exception
+ */
+ public void testInlineEnclosurePanelPage() throws Exception
+ {
+ executeTest(InlineEnclosurePanelPage.class, "InlineEnclosurePanelPageExpectedResult.html");
+ }
+
+ @Override
+ protected void setUp() throws Exception
+ {
+ WebApplication app = new WebApplication()
+ {
+ @Override
+ public Class<? extends Page> getHomePage()
+ {
+ return InlineEnclosurePage_1.class;
+ }
+
+ @Override
+ protected void init()
+ {
+ getMarkupSettings().setStripWicketTags(true);
+ }
+ };
+ tester = new WicketTester(app);
+ }
+
+
+}
\ No newline at end of file