org.apache.wicket.markup.resolver
Class ScopedComponentResolver

java.lang.Object
  extended by org.apache.wicket.markup.resolver.ScopedComponentResolver
All Implemented Interfaces:
Serializable, IClusterable, IComponentResolver

public class ScopedComponentResolver
extends Object
implements IComponentResolver

Implement a component resolver which walks up the component tree until a Page or Panel and tries to find a component with a matching wicket id, effectively providing something like scoping for wicket id resolution.

Note: This resolver is not activated by default. It has to be added by means of Application.getComponentResolvers().add(new InheritComponentResolver()) to be activated..

Example:

 MyPage()
 {
        add(new Label("hidden-by-cont1", "hidden"));
        add(new Label("global", "can be everywhere")); //the interesting case
 
        WebMarkupContainer cont1 = new WebMarkupContainer("cont1");
        add(cont1);
 
        cont1.add(new Label("hidden-by-cont1", "cont1 hides"));
        cont1.add(new Label("same-id", "cont1 same-id"));
 
        WebMarkupContainer cont2 = new WebMarkupContainer("cont2");
        add(cont2);
 
        cont2.add(new Label("same-id", "cont2 same-id"));
 }
 
 HTML:
 <html>
 <body>
   <span wicket:id="hidden-by-cont1">Prints: hidden</span>
   <div wicket:id="cont1">
     <span wicket:id="hidden-by-cont1">Prints: cont1 hides</span>
     <span wicket:id="same-id">Prints: cont1 same-id</span>
   </div>
 
   <div wicket:id="cont2">
     <span wicket:id="global">Prints: can be everywhere</span>
     <span wicket:id="same-id">Prints: cont2 same-id</span>
   </div>
 
So you can use the same ids in the same page. If the containing containers are not in the same hierarchy-line nothing changes. A comp with the same id hides the one of the parent-container with the same id.

Author:
Christian Essl, Juergen Donnerstag
See Also:
MarkupContainer.isTransparentResolver(), ParentResolver, Serialized Form

Constructor Summary
ScopedComponentResolver()
          Construct.
 
Method Summary
 boolean resolve(MarkupContainer container, MarkupStream markupStream, ComponentTag tag)
          Try to resolve the tag, then create a component, add it to the container and render it.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ScopedComponentResolver

public ScopedComponentResolver()
Construct.

Method Detail

resolve

public boolean resolve(MarkupContainer container,
                       MarkupStream markupStream,
                       ComponentTag tag)
Description copied from interface: IComponentResolver
Try to resolve the tag, then create a component, add it to the container and render it.

Specified by:
resolve in interface IComponentResolver
Parameters:
container - The container parsing its markup
markupStream - The current markupStream
tag - The current component tag while parsing the markup
Returns:
True if component-id was handled by the resolver, false otherwise.
See Also:
IComponentResolver.resolve(org.apache.wicket.MarkupContainer, org.apache.wicket.markup.MarkupStream, org.apache.wicket.markup.ComponentTag)


Copyright © 2004-2011 Apache Software Foundation. All Rights Reserved.