Wicket 1.3

Wicket In Action

The imports show the components that will be added as behaviors to the Index.java in this section:

import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.form.Button;
import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.markup.html.form.TextField;
import org.apache.wicket.markup.html.link.Link;

This Index class extends AbstractBasePage.java which extends WebPage which extends Component.
Component has an add method for adding a behavior to another Component like a WebPage.

… … … … … . . chapter01
… … … … … … . . section_1_3
… … … … … … … . Index.html
… … … … … … … . Index.java

Compare the html and java files to see how components are invoked and created.
Regarding the Hello World text:

1_3_1.jpg
and the Index class has:
    add(new Label("message", "Hello, World!"));

Regarding the link counter, see the "link" and "label" ids in Index.html.

        <div class="example">
            <a href="#" wicket:id="link">This link</a> has been clicked <span wicket:id="label">123</span> times.
        </div>

The text in the book does not match the source code example. In the book, the LinkCounter class extends WebPage, in the source, Index extends AbstractBasePage. In either case, Link is abstract and must be implemented using an anonymous sub-class.

1_3_3.jpg

Regarding the next example, the text echo, the example below from the book does not match the source code examples.
In the source code examples you have
final Label label = new Label("echo", new Model(""));
but from the book below, the label has an id of "message" and it is created as it is being added to the page.

See Index.html for the echo form markup.

The setModelObject() method is used to put the value of the TextField into the Label when the form submit button is clicked. Then use setModelObject("") on the textfield to clear it again for a new entry.

1_3_4.jpg
1_3_5.jpg1_3_6.jpgwicket_1_3.jpg1_3_2.jpg
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License