我正在为Wicket构建自定义FormComponentPanel
。这是在自己的Maven项目中完成的。
该项目后来作为依赖添加到我的webapp中。目前我的自定义面板没有
包含额外的功能。我在同一个包中有以下文件(在src / main / java / package下)。
CustomFormPanel.java:
class CustomFormPanel extends FormComponentPanel<String> {
public CustomFormPanel(final String id) {
super(id);
}
}
CustomFormPanel.html:
<wicket:panel>
</wicket:panel>
我使用以下组件:
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);
}
}
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>
如果我在浏览器中导航到此站点,则会收到以下错误消息:
Last cause: Failed to find markup file associated. CustomFormPanel: [CustomFormPanel [Component id = customPanel]]
答案 0 :(得分: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>
因此,位于.java
文件之外的资源将添加到构建中。
您可以查看Wicket quickstart默认配置。