You are viewing an old version of this page. View the current version.

Compare with Current View Page History

Version 1 Next »

Introduction

Wicket uses Java classes to represent pages. Most of the time, you will create a subclass of WebPage:

MyPage.java:

package org.wicket-wiki.example;
public class MyPage extends WebPage {}

And the markup MyPage.html:

<html>
<body>
... content ...
</body>
</html>

You can reach this class under the following URL:

See Newuserguide / The_Java_code for a verbose example.

Pages are objects too

Because pages are Java objects, you can create new instances and pass them around like any other object. You can use the constructor, for instance:

MyPage.java:

public class MyPage extends WebPage {
public MyPage(String name)

Unknown macro: { add(new Label("name", name)); }

}

Usage:

void onClick()

Unknown macro: { setResponsePage(new MyPage("keuner")); }

Because the entire page stays in the session, you do not have to put client related state (is this menu open?) in the session explicitly.

Reusing page header and footer

You can use markup inheritance with pages to re-use common markup like the header and footer.

Back Button Support

Pages can support the back button by enabling versioning with a call to setVersioned(boolean). If a Page is versioned and changes occur to it which need to be tracked, a verison manager will be installed using the overridable factory method newVersionManager(). The default version manager returned by the base implementation of this method is an instance of UndoPageVersionManager, which manages versions of a page by keeping change records that can be reversed at a later time.

Bookmarkable Pages

Pages can be constructed with any constructor when they are being used in a Wicket session, but if you wish to link to a Page using a URL that is "bookmarkable" (which implies that the URL will not have any session information encoded in it, and that you can call this page directly without having a session first directly from your browser), you need to implement your Page with a no-arg constructor or with a constructor that accepts a PageParameters argument (which wraps any query string parameters for a request). In case the page has both constructors, the constructor with PageParameters will be used.

See Bookmarkable nonBookmarkable pages for more information.

  • No labels