stevecross
stevecross

Reputation: 5684

Wicket fails to find markup file

I am building a custom FormComponentPanel for Wicket. This is done in its own Maven project. This project is later added to my webapp as a dependecy. At the moment my custom panel does not contain extra functionality. I have the following files inside the same package (under src/main/java/package).

CustomFormPanel.java:

class CustomFormPanel extends FormComponentPanel<String> {

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

}

CustomFormPanel.html:

<wicket:panel>

</wicket:panel>

I use this component as following:

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>

If I navigate to this site in my browser, I get following error message:

Last cause: Failed to find markup file associated. CustomFormPanel: [CustomFormPanel [Component id = customPanel]]

Upvotes: 2

Views: 5416

Answers (1)

ssssteffff
ssssteffff

Reputation: 974

You have to declare the src/main/java folder as a resource folder in you 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>

Thus, resources located besides your .java files will be added to the build.

You can take a look at the Wicket quickstart default configuration.

Upvotes: 6

Related Questions