Wicket wicket:id 继承 - 如何?

Wicket wicket:id inheritance - how to?

我是 wicket 的新手,尝试理解一些示例。我尝试的例子之一是 navomatic。纯示例适用于我的本地安装,下一步是将其扩展为示例应用程序。因此我给 "page" 一个简单的表格。

但我现在得到的是一个异常,如:

Last cause: Unable to find component with id 'form' in [BorderBodyContainer [Component id = navomaticBorder_body]]
Expected: 'navomaticBorder:bodyBorder:navomaticBorder_body:form'.
Found with similar names: 'form'

这是我的代码: NavomaticBorder.java

public class NavomaticBorder extends Border {

    public NavomaticBorder(final String id) {
        super(id);
        addToBorder(new MyBorder("navigationBorder"));
        addToBorder(new MyBorder("bodyBorder"));
    }
}

NavomaticBorder.html:

<html xmlns:wicket="http://wicket.apache.org">
<head>
<link rel="stylesheet" type="text/css" href="layout.css" />
</head>
<body>
   <wicket:border>
     <div id="main">
       <div id="left_nav">
         <span wicket:id="navigationBorder">
            <wicket:link>
                <a href="MyDataPage.html">My Data</a>
            </wicket:link>
        </span>
      </div>
      <div id="content_area">
         <span wicket:id="bodyBorder">
            <wicket:body />
         </span>
      </div>
    </div>
  </wicket:border>
</body>
</html>

MyDataPage.java:

public class MyDataPage extends WebPage {

    public MyDataPage() {
        add(new NavomaticBorder("navomaticBorder"));

        // This model references the page's message property and is
        // shared by the label and form component
        final PropertyModel<String> messageModel = new PropertyModel<>(this, "message");

        // The label displays the currently set message
        add(new Label("msg", messageModel));

        // Add a form to change the message. We don't need to do anything
        // else with this form as the shared model is automatically updated
        // on form submits
        final Form<?> form = new Form("form");
        form.add(new TextField("msgInput", messageModel));
        add(form);
    }
}

最后 MyDataPage.html:

<html xmlns:wicket="http://wicket.apache.org">
<head>
<link rel="stylesheet" type="text/css" href="layout.css" />
</head>
<body>
<!-- <div wicket:id = "mainNavigation"></div> -->
<div wicket:id = "navomaticBorder">
    <div>
        <h3>My Data</h3>
    </div>
    <div>
        <form wicket:id="form">
            <input type="text" wicket:id="msgInput" value="" size="50" />
            <input type="submit" value="set message" />
        </form>
        <span wicket:id="msg" id="msg">Message goes here</span>
    </div>
</div>

我猜这是一个继承问题,但我不确定如何解决它。 谁能给我一个解决方案的提示?

谢谢

您将表单放置在 novomaticBorder 中,但没有将其添加到您的组件层次结构中。

检票口代码:

  • navomaticBorder
  • 消息
  • 形式

标记:

  • navomaticBorder
    • 形式
    • 消息

您必须将表格添加到您的边框。

    NavomaticBorder navomaticBorder = new NavomaticBorder("navomaticBorder")
    add(navomaticBorder);

    //...

    navomaticBorder.add(form);

或者,您可以将组件排队而不是添加它们: https://ci.apache.org/projects/wicket/guide/7.x/guide/componentQueueing.html 排队将自动解析标​​记中的层次结构

    queue(new NavomaticBorder("navomaticBorder"));
    //...
    queue(form);