Apache Wicket - 结合教程

时间:2013-11-13 11:56:35

标签: html apache wicket

实际上,我必须学习wicket以获得实践课程,并且我遇到了一些问题。我试图结合wicket库中的两个wicket示例,但它失败了,我不知道为什么。 错误消息显示:

最后一个原因:无法在[BorderBodyContainer [Component id = navomaticBorder_body]]中找到ID为'form'的组件     预期:'navomaticBorder:navomaticBorder_body:form'。     找到相似的名字:'form'

我想要结合两个例子:navomatic side-bar在我的网站和简单的密码验证器之间有一些链接。

NavomaticBorder.java

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

NavomaticBorder.html

<html>
<head>
    <title>Wicket Examples - navomatic</title>
    <link rel="stylesheet" type="text/css" href="style.css"/>
</head>
<body>
<wicket:border> 
    <p>
    <table height = "100%">
        <tr>
            <td height = "100%" valign = "top">
                <div wicket:id = "navigationBorder">
                  <b>Navigation Links</b>
                  <p>
                    <wicket:link>
                      <a href = "Page1.html">Seite1</a><br/>
                      <a href = "Page2.html">Seite2</a><br/>
                      <a href = "Page3.html">Seite3</a>
                    </wicket:link>
                  </p>
                </div>
            </td>
            <td valign = "top">
                <span wicket:id = "bodyBorder">
                    <wicket:body/>
                </span>
            </td>
        </tr>
    </table>
    </p>
</wicket:border>
</body>
</html>

Page1.html

<html>
<head>
<title>Wicket Examples - navomatic</title>
<link rel="stylesheet" type="text/css" href="style.css"/>
</head>
<body>
<span wicket:id = "navomaticBorder">
    <h1>Registration 1</h1>
    <form wicket:id="form">
    <p><label>Username</label>:<input wicket:id="username" 
    type="text" size="20"></p>
    <p><label>Password</label>:<input wicket:id="password1" 
    type="password" size="20"></p>
    <p><label>Confirm Password</label>:<input wicket:id="password2" 
    type="password" size="20"></p>
    <input type="submit" value="Register">
</form>
<div wicket:id="feedback"></div>
</span>
</body>
</html>

Page1.java

public class Page1 extends WebPage {
/**
 * 
 */
private static final long serialVersionUID = 8070623982828503750L;
public Page1() {
    add(new NavomaticBorder("navomaticBorder"));
    add(new FeedbackPanel("feedback"));
    final TextField<?> username = new TextField<String>("username",
            Model.of(""));
    username.setRequired(true);
    FormComponent<String> password1 = new PasswordTextField("password1",
            Model.of(""));
    password1.setLabel(Model.of("Password"));
    password1.add(StringValidator.minimumLength(8));
    password1.add(new PasswordPolicyValidator());
    FormComponent<String> password2 = new PasswordTextField("password2",
            Model.of(""));
    Form<?> form = new Form<Void>("form") {
        private static final long serialVersionUID = -8653853765358238769L;

        @Override
        protected void onSubmit() {
            info("Form submitted");
        }
    };
    form.add(new EqualPasswordInputValidator(password1, password2));
    add(form);
    form.add(username);
    form.add(password1);
    form.add(password2);

}
}

我认为那可能导致错误的代码部分,当我让所有人单独工作时没有问题,就在我将这个结合在最后一个html文件中时,它抛出一个错误。 我没有真正的Html经验,也许这就是原因,但我希望它有足够的数据来帮助我:)。

里奇

1 个答案:

答案 0 :(得分:0)

它正在元素navomaticBorder中查找您的表单。因此,您应该将表单添加到navomaticBorder。 尝试将代码更改为:

public class Page1 extends WebPage {
/**
 * 
 */
private static final long serialVersionUID = 8070623982828503750L;
public Page1() {
    NavomaticBorder nav = new NavomaticBorder("navomaticBorder");
    add(nav);
    add(new FeedbackPanel("feedback"));
    final TextField<?> username = new TextField<String>("username",
            Model.of(""));
    username.setRequired(true);
    FormComponent<String> password1 = new PasswordTextField("password1",
            Model.of(""));
    password1.setLabel(Model.of("Password"));
    password1.add(StringValidator.minimumLength(8));
    password1.add(new PasswordPolicyValidator());
    FormComponent<String> password2 = new PasswordTextField("password2",
            Model.of(""));
    Form<?> form = new Form<Void>("form") {
        private static final long serialVersionUID = -8653853765358238769L;

        @Override
        protected void onSubmit() {
            info("Form submitted");
        }
    };
    form.add(new EqualPasswordInputValidator(password1, password2));
    nav.add(form);
    form.add(username);
    form.add(password1);
    form.add(password2);

}
}