简体   繁体   中英

Wicket Panel inside of a Fragment

是否可以在Fragment中添加面板(片段用于继承其他页面的页面),所以我也使用了标签)?

Yes, it is. Here's a simple example:

Page:

package com.mycompany;

import org.apache.wicket.request.mapper.parameter.PageParameters;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.panel.Fragment;
import org.apache.wicket.markup.html.WebPage;

public class HomePage extends WebPage {

    public HomePage(final PageParameters parameters) {
        super(parameters);

        Fragment fragment = new Fragment("fragment", "fragment-markup", this);

        fragment.add(new MyPanel("panel"));

        add(fragment);
    }
}

Page markup:

<!DOCTYPE html>
<html xmlns:wicket="http://wicket.apache.org">
    <body>
        <div wicket:id="fragment"/>

        <wicket:fragment wicket:id="fragment-markup">
            <div wicket:id="panel"/>
        </wicket:fragment>
    </body>
</html>

Panel:

package com.mycompany;

import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.panel.Panel;
import org.apache.wicket.model.Model;

public class MyPanel extends Panel {

    public MyPanel(String id) {
        super(id);

        add(new Label("hello", Model.of("Hello")));
        add(new Label("world", Model.of("World")));
    }

}

Panel markup:

<!DOCTYPE html>
<html>
<body>
    <wicket:panel>
        <div wicket:id="hello"/>
        <div wicket:id="world"/>
    </wicket:panel>
</body>
</html>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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