[ 
https://issues.apache.org/jira/browse/WICKET-6339?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15964055#comment-15964055
 ] 

Sven Ackermann commented on WICKET-6339:
----------------------------------------

Hi,

I tried to build a test case based on our setup, but this would get too 
complex. So I created a very simple test to illustrate the problem:
{code}
@Test
public void testSimple() {
        // application needed
        new WicketTester();

        // test markup
        Markup markup = Markup.of("<html><body><wicket:panel><wicket:container 
wicket:id='content'><a wicket:id='link' 
href='https://www.google.de'>Test</a></wicket:container></wicket:panel></body></html>");

        IMarkupFragment firstLevelfragment = markup.find("content");
        System.out.println(firstLevelfragment + " " + 
firstLevelfragment.size());

        // construct a new fragment for the link-Tag as sub-fragment of 
firstLevelfragment
        MarkupFragment secondLevelFragment = new 
MarkupFragment(firstLevelfragment, 1);
        System.out.println(secondLevelFragment + " " + 
secondLevelFragment.size());

        List<MarkupElement> iteratorElements = new 
ArrayList<>(secondLevelFragment.size());
        for (MarkupElement markupElement : secondLevelFragment) {
                iteratorElements.add(markupElement);
        }
        List<MarkupElement> getElements = new 
ArrayList<>(secondLevelFragment.size());
        for (int i = 0; i < secondLevelFragment.size(); i++) {
                getElements.add(secondLevelFragment.get(i));
        }

        // elements from iterator should match the ones from the get(i) method
        assertEquals(getElements, iteratorElements);
}
{code}

As I mentioned, we have a very special usecase where we use some Wicket APIs 
that are not commonly used. We also have a workaround (using 
{{MarkupFragment.get(int)}} and {{MarkupFragment.size()}} instead of 
{{MarkupFragment.iterator()}}). I just wanted to tell you, that there might be 
sth. wrong in your code. If you think it's too risky to change sth. here, I can 
totally understand that.

To describe our usecase a bit:
We have a special subclass of {{MarkupContainer}} that loads its content from a 
CMS. Within that static content we look for all links and manipulate the markup 
in a way that these links are replaced with Wicket AjaxLinks to add some 
special handling (basically sth. like a confirmation "Do you really want to 
click this link?"). I know that our solution is maybe not the best way to do 
that, but there were some requirements to do it like this. In the setup we use 
the APIs of {{Markup}}, {{IMarkupFragment}}, {{AbstractMarkupParser}}, 
{{AbstractMarkupFilter}} and {{ComponentTag}}.
If we use the {{MarkupFragment.iterator()}} method, we get the following error 
which I debugged down to the described problem:
{quote}
Tag expected
 MarkupStream: [markup = 
org.apache.wicket.util.resource.StringResourceStream@7ce97bef: <a 
href="https://www.google.de/"; target="_blank">Test</a>

        <wicket:container wicket:id="content"><a href="https://www.google.de/"; 
target="_blank">Test</a>, index = 0, current = [Raw markup]]
        at 
org.apache.wicket.markup.MarkupStream.throwMarkupException(MarkupStream.java:526)
        at org.apache.wicket.markup.MarkupStream.getTag(MarkupStream.java:258)
        at 
org.apache.wicket.Component.internalRenderComponent(Component.java:2517)
        at org.apache.wicket.MarkupContainer.onRender(MarkupContainer.java:1698)
        at org.apache.wicket.Component.internalRender(Component.java:2380)
        at org.apache.wicket.Component.render(Component.java:2308)
        at 
org.apache.wicket.MarkupContainer.renderNext(MarkupContainer.java:1524)
        at 
org.apache.wicket.MarkupContainer.renderAll(MarkupContainer.java:1759)
        at 
org.apache.wicket.MarkupContainer.renderComponentTagBody(MarkupContainer.java:1734)
        at 
org.apache.wicket.MarkupContainer.renderAssociatedMarkup(MarkupContainer.java:797)
        at 
org.apache.wicket.markup.html.panel.AssociatedMarkupSourcingStrategy.renderAssociatedMarkup(AssociatedMarkupSourcingStrategy.java:77)
        at 
org.apache.wicket.markup.html.panel.PanelMarkupSourcingStrategy.onComponentTagBody(PanelMarkupSourcingStrategy.java:112)
        at 
org.apache.wicket.Component.internalRenderComponent(Component.java:2565)
        at org.apache.wicket.MarkupContainer.onRender(MarkupContainer.java:1698)
        at org.apache.wicket.Component.internalRender(Component.java:2380)
        at org.apache.wicket.Component.render(Component.java:2308)
        at 
org.apache.wicket.MarkupContainer.renderNext(MarkupContainer.java:1524)
        at 
org.apache.wicket.MarkupContainer.renderAll(MarkupContainer.java:1759)
        at org.apache.wicket.Page.onRender(Page.java:879)
        at org.apache.wicket.markup.html.WebPage.onRender(WebPage.java:141)
        at org.apache.wicket.Component.internalRender(Component.java:2380)
        at org.apache.wicket.Component.render(Component.java:2308)
        at org.apache.wicket.Page.renderPage(Page.java:1018)
        at 
org.apache.wicket.request.handler.render.WebPageRenderer.renderPage(WebPageRenderer.java:124)
        at 
org.apache.wicket.request.handler.render.WebPageRenderer.respond(WebPageRenderer.java:236)
        at 
org.apache.wicket.util.tester.BaseWicketTester$LastPageRecordingPageRendererProvider$1.respond(BaseWicketTester.java:2747)
        at 
org.apache.wicket.core.request.handler.RenderPageRequestHandler.respond(RenderPageRequestHandler.java:175)
        at 
org.apache.wicket.request.cycle.RequestCycle$HandlerExecutor.respond(RequestCycle.java:895)
        at 
org.apache.wicket.request.RequestHandlerStack.execute(RequestHandlerStack.java:64)
        at 
org.apache.wicket.request.cycle.RequestCycle.execute(RequestCycle.java:265)
        at 
org.apache.wicket.request.cycle.RequestCycle.processRequest(RequestCycle.java:222)
        at 
org.apache.wicket.request.cycle.RequestCycle.processRequestAndDetach(RequestCycle.java:293)
        at 
org.apache.wicket.util.tester.BaseWicketTester.processRequest(BaseWicketTester.java:718)
        at 
org.apache.wicket.util.tester.BaseWicketTester.processRequest(BaseWicketTester.java:657)
        at 
org.apache.wicket.util.tester.BaseWicketTester.startPage(BaseWicketTester.java:887)
        at 
org.apache.wicket.util.tester.BaseWicketTester.startPage(BaseWicketTester.java:904)
        at 
org.apache.wicket.util.tester.BaseWicketTester.startComponentInPage(BaseWicketTester.java:1466)
        at 
org.apache.wicket.util.tester.BaseWicketTester.startComponentInPage(BaseWicketTester.java:1386)
{quote}

> Wrong implementation of MarkupFragment.iterator()
> -------------------------------------------------
>
>                 Key: WICKET-6339
>                 URL: https://issues.apache.org/jira/browse/WICKET-6339
>             Project: Wicket
>          Issue Type: Bug
>          Components: wicket
>    Affects Versions: 7.2.0
>            Reporter: Sven Ackermann
>
> The method returns {{getRootMarkup().iterator(startIndex, size)}}, but this 
> only works when {{getRootMarkup() == getParentMarkup()}} or all intermediate 
> {{MarkupFragment}}s start at index 0.
> The {{startIndex}} of all intermediate {{MarkupFragment}}s must be added, 
> otherwise the iterator starts at a wrong index.



--
This message was sent by Atlassian JIRA
(v6.3.15#6346)

Reply via email to