Hi all,

In the application I am writing I have encountered a need for
polymorphic components. That is, in my markup I have

    <span wicket:id="blah">content</span>

and depending on what component is used on the server side, I can add
links, labels, or anything else you can imagine. The only requirement is
that the component provides its own html. This is very useful for
instance for dynamically generating content such as dynamic menus based
on user privileges where the menu items consist of plain text, links,
images, etc....

As an example I have attached a LinkPanel. The programmer has to create
a subclass and implement

   /**   
     * Must be implemented to create the content of the link.
     * @param aId Id of the component to create.
     */
    protected abstract Component createContent(String aId);
   
   
    /**
     * Callback to notify the user of onClick events.
     *
     */
    protected abstract void onClick();


The first callback is simply to create the content. The second is to
notify of onclick events.  The html template for the component is very
simple, just an anchor and the content of the anchor.

Are a range of components like this a good idea for inclusion in
wicket-extensions?

Cheers
  Erik

PS. This is a wicket 1.2.2 component but wicket 2 would be really easy.

import wicket.Component;
import wicket.markup.html.link.Link;
import wicket.markup.html.panel.Panel;

/**
 * Represents a link with text marked up in a specific way.
 * This generates a link with CSS class <code>link</code>.
 */
public abstract class LinkPanel extends Panel {
   
    /**
     * Constructs the link.
     * @param aId Id of the link.
     */
    public LinkPanel(String aId) {
        super(aId);
        Link link = new Link("link") {
            @Override
            public void onClick() {
                LinkPanel.this.onClick();
            }
        };
        link.add(createContent("text"));
        add(link);
    }
   
    /**
     * Must be implemented to create the content of the link.
     * @param aId Id of the component to create.
     */
    protected abstract Component createContent(String aId);
   
   
    /**
     * Callback to notify the user of onClick events.
     *
     */
    protected abstract void onClick();
}

HTML template


<html>
    <head>
       
    </head>
    <body>
        <wicket:panel>
            <a class="link" wicket:id="link"><span wicket:id="text">Link
text</span></a>
        </wicket:panel>
    </body>
</html>


-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Wicket-user mailing list
Wicket-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/wicket-user

Reply via email to