Hi,

I'm trying to use IComponentResolver to implement a custom tag that will render a panel with a link that when clicked will display some help text. I want to use a custom tag for this because I need to be able to programmatically validate up-front (during the build process) that there are no missing help texts (=unknown help text IDs) in the code base. Parsing XHTML to do so is obviously way easier than parsing the application's java sources so that's why I opted for the IComponentResolver approach.

My component resolver:

--->8------>8------>8------>8------>8------>8------>8---
    @Override
public Component resolve(MarkupContainer container, MarkupStream markupStream, ComponentTag tag)
    {
if ( markupStream.getWicketNamespace().equalsIgnoreCase( tag.getNamespace() ) && TAG_NAME.equalsIgnoreCase( tag.getName() ) )
        {
            final String tagValue = tag.getAttribute("helpTextId");
return new HelpTextTag( "helpText."+container.getPage().getAutoIndex() , new HelpTextId( tagValue.trim() ) );
        }
        return null;
    }
--->8------>8------>8------>8------>8------>8------>8---


HelpTextTag is a very simple panel:

--->8------>8------>8------>8------>8------>8---
<?xml version="1.0" encoding="UTF-8"?>
<html xmlns="http://www.w3.org/1999/xhtml"; xmlns:wicket="http://wicket.apache.org/";>
  <body>
    <wicket:panel>
        <div>
<a wicket:id="helpTextLink"><img wicket:id="helpTextImg" width="16" height="16" />Help</a>
        </div>
    </wicket:panel>
  </body>
</html>

--->8------>8------>8------>8------>8------>8---
public class HelpTextTag extends Panel
{
    private final HelpTextId helpTextId;

    public HelpTextTag(String id,HelpTextId helpTextId)
    {
        super(id);
        this.helpTextId = helpTextId;
    }

    @Override
    protected void onInitialize()
    {
        super.onInitialize();
        final Link<String> l = new Link<String>("helpTextLink")
        {
            @Override
public void onClick() { setResponsePage( new HelpPage(helpTextId) ); }
        };
l.add( new Image("helpTextImg" , new PackageResourceReference("img/help.png") ) );
        add(l);
    }
}
--->8------>8------>8------>8------>8------>8------>8---

Most likely due to my lack of understanding how IComponentResolver really fits into the grand scheme of things :) , trying to click the link always fails with a "Could not find component ... on page" Exception ... which kind of makes sense since the HelpTextTag is not add()ed to the component hierarchy (at least not by me).

Here's the markup generated by Wicket:

--->8------>8------>8------>8------>8------>8------>8---
<wicket:extend>
<wicket:help wicketsource="com.voipfuture.voipmng.onlinehelp:HelpTextTagResolver.java:36" helptextid="test.page"><wicket:panel><!-- MARKUP FOR com.voipfuture.voipmng.onlinehelp.HelpTextTag BEGIN -->
      <div>
<a wicketsource="com.voipfuture.voipmng.onlinehelp:HelpTextTag.java:23" href="../page?2-1.ILinkListener-_wicket_child11-_wicket_extend12-_wicket_child67-_wicket_extend68-helpText.69-helpTextLink" wicket:id="helpTextLink"> <img width="16" height="16" wicketsource="com.voipfuture.voipmng.onlinehelp:HelpTextTag.java:31" src="../resource/org.apache.wicket.Application/img/help-ver-1375187674000.png" wicket:id="helpTextImg">
         </a>
         Help
      </div>
<!-- MARKUP FOR com.voipfuture.voipmng.onlinehelp.HelpTextTag END --></wicket:panel></wicket:help> <a wicketsource="com.vodecc.voipmng.boundary.wicket.onlinehelp:HelpTextsOverviewPage.java:20" href="../page?2-1.ILinkListener-someOtherLink" wicket:id="someOtherLink">Some link</a>
  </wicket:extend>
--->8------>8------>8------>8------>8------>8------>8---

Is it even possible to add a new Panel/component without it already being present in the component hierarchy ? I looked at the IComponentResolver implementations that ship with Wicket and they either just generate/rewrite existing markup or replace a component that has already been added to the page.

Thanks,
Tobias


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org

Reply via email to