Wicket wicket:id继承 - 怎么样?

时间:2016-08-24 13:09:09

标签: border wicket

我是wicket的新手试图了解一些例子。我尝试的一个例子是navomatic。纯示例适用于我的本地安装,我的下一步是将其扩展为示例应用程序。因此我把“页面”放在一个简单的表格中。

但我现在得到的是一个例外情况:

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>

我想这是一个遗产问题,但我不知道如何解决它。 任何人都可以给我一个解决方案的提示吗?

感谢

1 个答案:

答案 0 :(得分:4)

您已将表单放在novomaticBorder中,但未将其添加到组件层次结构中。

Wicket Code:

  • navomaticBorder
  • MSG
  • 形式

标记:

  • navomaticBorder
    • 形式
    • MSG

您必须将表单添加到边框。

    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);