简体   繁体   English

小门:面板嵌套为组件

[英]Wicket: Panel nesting as component

Is it possible (or what is the best way) to have own Panel with Component behaviours? 是否有可能(或最好的方法)是拥有带有组件行为的面板? Especially with HTML nesting... 特别是HTML嵌套...

I want something like that: 我想要这样的东西:

    public HeaderPanel(String id) { /* extends Wicket Panel */
        super(id);

        add(new Link(ID_HOME_LINK, null) {
            private static final long serialVersionUID = 1L;

            {
                add(new Image(ID_HOME_LOGO, new ContextRelativeResource("img/logo.png")));              
            }

            @Override
            public void onClick(AjaxRequestTarget target) {
                setResponsePage(((BasicPage)getPage()).getLogoLinkPage());
            }
        });      
    }

With HTML: 使用HTML:

<!DOCTYPE html>
<html>
    <body>
        <wicket:panel>
             <a wicket:id="home-link">
                <img wicket:id="home-logo" src="img/logo.png" title="LearnMe" style="max-height: 65px;" />  <!-- HERE is problem - I would like to set children here -->
             </a>
        </wicket:panel>
    </body>
</html>

And this is the intent in Link (it is my "customized" panel that handles links): 这就是链接的意图(这是我的“定制”面板来处理链接):

public Link(String id, IModel<String> model, boolean ajax) { /* Extends Wicket Panel */
        super(id);
        this.ajax = ajax;
        this.model = model;

        setRenderBodyOnly(true);

         if (ajax) {        
                add(link = new AjaxLink<String>(ID_LINK) {

                    @Override   
                    public void onClick(AjaxRequestTarget target) {
                        Link.this.onClick(target);                  
                    }
                });
            } else {
                add(link = new org.apache.wicket.markup.html.link.Link<String>(ID_LINK) {

                    @Override
                    public void onClick() {
                        Link.this.onClick(null);    
                    }
                });
            }
    }

With appropriate HTML: 使用适当的HTML:

<html>
    <body>
        <wicket:panel>
            <a wicket:id="link"></a> <!-- HERE is problem - I don't know, which ones and how many components go there  -->
        </wicket:panel>
    </body>
</html>

Now I get this Exception: 现在我得到这个异常:

Last cause: Close tag not found for tag: <a wicket:id="home-link" id="home_link3">. For  Components only raw markup is allow in between the tags but not other Wicket Component. Component: [Link [Component id = home-link]]

Maybe I am wrong with Panel capacibility or doing unnecessary thing with Link component, but I am looking for idea of nesting/inheriting Panels in one template like it is usual with Components in Wicket (like HeaderPanel Link were Wicket Link, not my customized Panel "Link" - that works, but it is not "common" solution). 也许我在面板功能上是错的,或者在Link组件上做了不必要的事情,但是我正在寻找在一个模板中嵌套/继承面板的想法,就像在Wicket中使用组件一样(例如HeaderPanel链接是Wicket链接,而不是我的自定义面板“链接”-有效,但不是“通用”解决方案)。

Your problem is in Link.html . 您的问题出在Link.html There you have a <a wicket:id="link" for the Wicket's Link but you do not have HTML element for the image. 在那里,Wicket的链接具有<a wicket:id="link" ,但是图像没有HTML元素。 The one defined in HeaderPanel.html is completely overridden by the markup provided by (your) Link.html. HeaderPanel.html中定义的那个被(您的)Link.html提供的标记完全覆盖。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM