是否可以在Extend组件中使用Wicket Fragments?

时间:2013-03-18 00:19:57

标签: wicket wicket-1.5

我正在尝试在Extend组件中使用Fragments,但它会抛出MarkupNotFoundException。

代码与此类似:

BasePanel.html

<?xml version="1.0" encoding="UTF-8" ?>
<wicket:panel xmlns:wicket="http://wicket.apache.org">

    <div wicket:id="dialog">
        <div class="titlebar">
            <h3 wicket:id="dialogTitle">[[ dialog title ]]</h3>
            <div wicket:id="dialogCloseBtn" class="closeBtn right"></div>
        </div>
        <wicket:child />
    </div>

</wicket:panel>

ChildPanel.html

<?xml version="1.0" encoding="UTF-8" ?>

<wicket:extend xmlns:wicket="http://wicket.apache.org">

    <wicket:panel wicket:id="panel1" />

    <wicket:fragment wicket:id="fragment1">
    </wicket:fragment>

</wicket:extend>

ChildPanel.java

public class ChildPanel extends Panel  
{
    public ChildPanel(String id, IModel<?> model) 
    {
         super(id, model);
         add(new Fragment("panel1", "fragment1", this); 
    }
}

问题在于Wicket Markup.java 类:

public final IMarkupFragment find(final String id)
{
    Args.notEmpty(id, "id");

    MarkupStream stream = new MarkupStream(this);
    stream.setCurrentIndex(0);
    while (stream.hasMore())
    {
        MarkupElement elem = stream.get();
        if (elem instanceof ComponentTag)
        {
            ComponentTag tag = stream.getTag();
            if (tag.isOpen() || tag.isOpenClose())
            {
                if (tag.getId().equals(id))
                {
                    return stream.getMarkupFragment();
                }
                if (tag.isOpen() && !tag.hasNoCloseTag() && !(tag instanceof WicketTag) &&
                    !"head".equals(tag.getName()) && !tag.isAutoComponentTag())
                {
                    stream.skipToMatchingCloseTag(tag);
                }
            }
        }

        stream.next();
    }

    return null;
}

当应用程序遍历流时,它会在 BasePanel标记中查找。查看开放标记<div wicket:id="dialog">后,它会迭代到结束标记</div>,因此它不会查看 ChildPanel标记

您有任何建议或解决方案吗?

谢谢, 曼努埃尔

2 个答案:

答案 0 :(得分:1)

有一个与此主题相关的已打开的jira问题。您可以按照说明在此处解决:https://issues.apache.org/jira/browse/WICKET-4545

答案 1 :(得分:0)

您可以在<wicket:fragment>内声明<wicket:extend>,但不能在<wicket:panel>(面板1)中声明。请尝试使用<wicket:container>