You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@wicket.apache.org by iv...@apache.org on 2007/03/29 21:38:49 UTC

svn commit: r523814 - in /incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/wicket: Application.java markup/WicketTag.java markup/resolver/WicketContainerResolver.java

Author: ivaynberg
Date: Thu Mar 29 12:38:48 2007
New Revision: 523814

URL: http://svn.apache.org/viewvc?view=rev&rev=523814
Log:
WICKET-11 added wicket:container tag support

Added:
    incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/wicket/markup/resolver/WicketContainerResolver.java
Modified:
    incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/wicket/Application.java
    incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/wicket/markup/WicketTag.java

Modified: incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/wicket/Application.java
URL: http://svn.apache.org/viewvc/incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/wicket/Application.java?view=diff&rev=523814&r1=523813&r2=523814
==============================================================================
--- incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/wicket/Application.java (original)
+++ incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/wicket/Application.java Thu Mar 29 12:38:48 2007
@@ -40,6 +40,7 @@
 import wicket.markup.resolver.HtmlHeaderResolver;
 import wicket.markup.resolver.MarkupInheritanceResolver;
 import wicket.markup.resolver.ParentResolver;
+import wicket.markup.resolver.WicketContainerResolver;
 import wicket.markup.resolver.WicketLinkResolver;
 import wicket.markup.resolver.WicketMessageResolver;
 import wicket.protocol.http.IRequestLogger;
@@ -877,6 +878,7 @@
 		pageSettings.addComponentResolver(new WicketMessageResolver());
 		pageSettings.addComponentResolver(new FragmentResolver());
 		pageSettings.addComponentResolver(new EnclosureResolver());
+		pageSettings.addComponentResolver(new WicketContainerResolver());
 		
 		// Install button image resource factory
 		getResourceSettings().addResourceFactory("buttonFactory",

Modified: incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/wicket/markup/WicketTag.java
URL: http://svn.apache.org/viewvc/incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/wicket/markup/WicketTag.java?view=diff&rev=523814&r1=523813&r2=523814
==============================================================================
--- incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/wicket/markup/WicketTag.java (original)
+++ incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/wicket/markup/WicketTag.java Thu Mar 29 12:38:48 2007
@@ -87,6 +87,14 @@
 	}
 
 	/**
+	 * @return True, if tag name equals 'wicket:container'
+	 */
+	public final boolean isContainerTag()
+	{
+		return "container".equalsIgnoreCase(getName());
+	}
+
+	/**
 	 * @return True, if tag name equals 'wicket:child'
 	 */
 	public final boolean isChildTag()

Added: incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/wicket/markup/resolver/WicketContainerResolver.java
URL: http://svn.apache.org/viewvc/incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/wicket/markup/resolver/WicketContainerResolver.java?view=auto&rev=523814
==============================================================================
--- incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/wicket/markup/resolver/WicketContainerResolver.java (added)
+++ incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/wicket/markup/resolver/WicketContainerResolver.java Thu Mar 29 12:38:48 2007
@@ -0,0 +1,96 @@
+/*
+ * 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 wicket.markup.resolver;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import wicket.MarkupContainer;
+import wicket.markup.ComponentTag;
+import wicket.markup.MarkupStream;
+import wicket.markup.parser.filter.WicketTagIdentifier;
+
+/**
+ * This is a tag resolver which handles <wicket:container>
+ * 
+ * Sometimes adding components in certain ways may lead to output of invalid
+ * markup. For example, lets pretend we output table rows two at a time using a
+ * repeater. The markup would look something like this:
+ * 
+ * <code>
+ * 	<table>
+ * 		<span wicket:id="repeater">
+ * 			<tr><td>...</td></tr>
+ * 			<tr><td>...</td></tr>
+ * 		</span>
+ * 	</table>
+ * </code>
+ * 
+ * Notice that we had to attach the repeater to a component tag - in this case a
+ * <code>span</code>, but a span is not a legal tag to nest under
+ * <code>table</code>. So we can rewrite the example as following:
+ * 
+ * <code>
+ * 	<table>
+ * 		<wicket:container wicket:id="repeater">
+ * 			<tr><td>...</td></tr>
+ * 			<tr><td>...</td></tr>
+ * 		</wicket:container>
+ * 	</table>
+ * </code>
+ * 
+ * The above is valid markup because wicket namespaced tags are allowed anywhere
+ * 
+ * @author Igor Vaynberg (ivaynberg)
+ */
+public class WicketContainerResolver implements IComponentResolver
+{
+	private static final Log log = LogFactory.getLog(WicketContainerResolver.class);
+
+	static
+	{
+		// register "wicket:container"
+		WicketTagIdentifier.registerWellKnownTagName("container");
+	}
+
+
+	private static final long serialVersionUID = 1L;
+
+	/**
+	 * Try to resolve the tag, then create a component, add it to the container
+	 * and render it.
+	 * 
+	 * @see wicket.markup.resolver.IComponentResolver#resolve(MarkupContainer,
+	 *      MarkupStream, ComponentTag)
+	 * 
+	 * @param container
+	 *            The container parsing its markup
+	 * @param markupStream
+	 *            The current markupStream
+	 * @param tag
+	 *            The current component tag while parsing the markup
+	 * @return true, if componentId was handle by the resolver. False, otherwise
+	 */
+	public boolean resolve(final MarkupContainer container, final MarkupStream markupStream,
+			final ComponentTag tag)
+	{
+		// this is only here so we register wicket:container tag, this resolver
+		// does not actually do anything special to the tag
+		return false;
+	}
+
+}
\ No newline at end of file