Author: jdonnerstag
Date: Mon Dec 28 10:55:37 2009
New Revision: 894148

URL: http://svn.apache.org/viewvc?rev=894148&view=rev
Log:
create 'auto' components when markup becomes available. They'll be added like 
normal components and not removed at end of the request.

Modified:
    wicket/trunk/wicket/src/main/java/org/apache/wicket/Component.java
    wicket/trunk/wicket/src/main/java/org/apache/wicket/MarkupContainer.java
    wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/MarkupStream.java
    
wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/resolver/ComponentResolvers.java
    
wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/resolver/WicketContainerResolver.java

Modified: wicket/trunk/wicket/src/main/java/org/apache/wicket/Component.java
URL: 
http://svn.apache.org/viewvc/wicket/trunk/wicket/src/main/java/org/apache/wicket/Component.java?rev=894148&r1=894147&r2=894148&view=diff
==============================================================================
--- wicket/trunk/wicket/src/main/java/org/apache/wicket/Component.java 
(original)
+++ wicket/trunk/wicket/src/main/java/org/apache/wicket/Component.java Mon Dec 
28 10:55:37 2009
@@ -751,6 +751,7 @@
                        log.debug("Markup available " + toString());
                }
 
+               // get the markup ID from the markup if available
                markuIdFromMarkup = getMarkupIdFromMarkup();
        }
 

Modified: 
wicket/trunk/wicket/src/main/java/org/apache/wicket/MarkupContainer.java
URL: 
http://svn.apache.org/viewvc/wicket/trunk/wicket/src/main/java/org/apache/wicket/MarkupContainer.java?rev=894148&r1=894147&r2=894148&view=diff
==============================================================================
--- wicket/trunk/wicket/src/main/java/org/apache/wicket/MarkupContainer.java 
(original)
+++ wicket/trunk/wicket/src/main/java/org/apache/wicket/MarkupContainer.java 
Mon Dec 28 10:55:37 2009
@@ -1462,6 +1462,10 @@
                        if (component == null)
                        {
                                component = ComponentResolvers.resolve(this, 
markupStream, tag);
+                               if ((component != null) && 
(component.getParent() == null))
+                               {
+                                       autoAdd(component, markupStream);
+                               }
                        }
 
                        // Failed to find it?
@@ -1978,4 +1982,59 @@
                        list.childs[idx2] = tmp;
                }
        }
+
+       /**
+        * @see org.apache.wicket.Component#onMarkupAttached()
+        */
+       @Override
+       protected void onMarkupAttached()
+       {
+               super.onMarkupAttached();
+
+               // Automatically create components for <wicket:xxx> tag.
+               IMarkupFragment markup = getMarkup();
+               if ((markup != null) && (markup.size() > 1))
+               {
+                       // Skip the first component tag which already belongs 
to 'this' container
+                       MarkupStream stream = new MarkupStream(markup);
+                       for (; stream.hasMore(); stream.next())
+                       {
+                               MarkupElement elem = stream.get();
+                               if (elem instanceof ComponentTag)
+                               {
+                                       stream.next();
+                                       break;
+                               }
+                       }
+
+                       // Search for <wicket:xxx> in the remaining markup and 
try to resolve the component
+                       for (; stream.hasMore(); stream.next())
+                       {
+                               MarkupElement elem = stream.get();
+                               if (elem instanceof ComponentTag)
+                               {
+                                       ComponentTag tag = (ComponentTag)elem;
+                                       if (tag.isOpen() || tag.isOpenClose())
+                                       {
+                                               if (elem instanceof WicketTag)
+                                               {
+                                                       Component component = 
ComponentResolvers.resolve(this, stream, tag);
+                                                       if ((component != null) 
&& (component.getParent() == null))
+                                                       {
+                                                               // make sure we 
are able to get() the component during rendering
+                                                               
tag.setId(component.getId());
+
+                                                               add(component);
+                                                       }
+                                               }
+
+                                               if (tag.isOpen())
+                                               {
+                                                       
stream.skipToMatchingCloseTag(tag);
+                                               }
+                                       }
+                               }
+                       }
+               }
+       }
 }

Modified: 
wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/MarkupStream.java
URL: 
http://svn.apache.org/viewvc/wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/MarkupStream.java?rev=894148&r1=894147&r2=894148&view=diff
==============================================================================
--- 
wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/MarkupStream.java 
(original)
+++ 
wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/MarkupStream.java 
Mon Dec 28 10:55:37 2009
@@ -17,6 +17,7 @@
 package org.apache.wicket.markup;
 
 import org.apache.wicket.Component;
+import org.apache.wicket.util.lang.Checks;
 import org.apache.wicket.util.resource.IResourceStream;
 import org.apache.wicket.util.string.Strings;
 
@@ -61,6 +62,7 @@
         */
        public MarkupStream(final IMarkupFragment markup)
        {
+               Checks.argumentNotNull(markup, "markup");
                this.markup = markup;
 
                if (markup.size() > 0)

Modified: 
wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/resolver/ComponentResolvers.java
URL: 
http://svn.apache.org/viewvc/wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/resolver/ComponentResolvers.java?rev=894148&r1=894147&r2=894148&view=diff
==============================================================================
--- 
wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/resolver/ComponentResolvers.java
 (original)
+++ 
wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/resolver/ComponentResolvers.java
 Mon Dec 28 10:55:37 2009
@@ -60,10 +60,6 @@
                                Component component = 
resolver.resolve(container, markupStream, tag);
                                if (component != null)
                                {
-                                       if (component.getParent() == null)
-                                       {
-                                               container.autoAdd(component, 
markupStream);
-                                       }
                                        return component;
                                }
                        }
@@ -79,7 +75,6 @@
                        Component component = resolver.resolve(container, 
markupStream, tag);
                        if (component != null)
                        {
-                               container.autoAdd(component, markupStream);
                                return component;
                        }
                }

Modified: 
wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/resolver/WicketContainerResolver.java
URL: 
http://svn.apache.org/viewvc/wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/resolver/WicketContainerResolver.java?rev=894148&r1=894147&r2=894148&view=diff
==============================================================================
--- 
wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/resolver/WicketContainerResolver.java
 (original)
+++ 
wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/resolver/WicketContainerResolver.java
 Mon Dec 28 10:55:37 2009
@@ -21,7 +21,6 @@
 import org.apache.wicket.markup.ComponentTag;
 import org.apache.wicket.markup.MarkupStream;
 import org.apache.wicket.markup.WicketTag;
-import org.apache.wicket.markup.parser.filter.TransparentWebMarkupContainer;
 import org.apache.wicket.markup.parser.filter.WicketTagIdentifier;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -81,12 +80,7 @@
        {
                if (tag instanceof WicketTag)
                {
-                       final WicketTag wTag = (WicketTag)tag;
-
-                       // this is only here so we register wicket:container 
tag, this resolver
-                       // does not actually do anything special to the tag
-                       String id = wTag.getId() + 
container.getPage().getAutoIndex();
-                       return new TransparentWebMarkupContainer(id);
+                       return container.get(tag.getId());
                }
                return null;
        }


Reply via email to