Wicket无法找到标记文件

ste*_*oss 2 java wicket

我正在FormComponentPanel为Wicket 建立一个定制.这是在自己的Maven项目中完成的.该项目后来作为依赖项添加到我的webapp中.目前,我的自定义面板不包含额外功能.我在同一个包里面有以下文件(在src/main/java/package下).

CustomFormPanel.java:

class CustomFormPanel extends FormComponentPanel<String> {

    public CustomFormPanel(final String id) {
        super(id);
    }

}
Run Code Online (Sandbox Code Playgroud)

CustomFormPanel.html:

<wicket:panel>

</wicket:panel>
Run Code Online (Sandbox Code Playgroud)

我使用这个组件如下:

CustomPage.java:

public class CustomPage extends WebPage {

    private final StatelessForm<Void> form;

    private FormComponentPanel<String> customPanel;

    public CustomPage(final PageParameters params) {
        super(params);

        customPanel = new CustomFormPanel("customPanel");

        form = new StatelessForm<Void>("form") {

            @Override
            public void onSubmit() {
                final String param = customPanel.getModelObject();
            }

        };
    }

    @Override
    public void onInitialize() {
        super.onInitialize();

        form.add(customPanel);
        add(form);
    }

}
Run Code Online (Sandbox Code Playgroud)

CustomPage.html:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:wicket="http://wicket.apache.org">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
    <form wicket:id="form">
        <wicket:container wicket:id="customPanel"></wicket:container>
        <input type="submit" value="Job erstellen" />
    </form>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)

如果我在浏览器中导航到此站点,则会收到以下错误消息:

Last cause: Failed to find markup file associated. CustomFormPanel: [CustomFormPanel [Component id = customPanel]]
Run Code Online (Sandbox Code Playgroud)

sss*_*fff 5

您必须src/main/java在pom.xml中将该文件夹声明为资源文件夹.

<resources>
    <resource>
        <filtering>false</filtering>
        <directory>src/main/resources</directory>
    </resource>
    <resource>
        <filtering>false</filtering>
        <directory>src/main/java</directory>
        <includes>
            <include>**</include>
        </includes>
        <excludes>
            <exclude>**/*.java</exclude>
        </excludes>
    </resource>
</resources>
Run Code Online (Sandbox Code Playgroud)

因此,位于.java文件旁边的资源将添加到构建中.

您可以查看Wicket快速入门默认配置.