0

actually i have to learn wicket for a practical course and I have some problems. i tried to combine two of the wicket examples from the wicket library, but it failed and i dont know why. The error message says:

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

There are two examples i want to combine: the navomatic side-bar to have some links between my sites and a simple password validator.

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

}
}

I think thats the code parts who may cause the error, when i let all of them working alone theres no problem, just when i combine this in the last html file, its throwing an error. I have no real experience with Html, maybe thats the cause but i hope its enough data to help me :)

Richie

4

1 回答 1

0

It's looking for your form in the element navomaticBorder. So you should add the form to the navomaticBorder. Try changing your code to this:

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

}
}
于 2013-11-13T14:50:28.893 回答