0
votes

Thats a general question about: How to structure my website with all its pages and components (here panels) in wicket. I would like to show my attempt and hope someone can give me advice, wheather its a good way or if there is a better one.

My Structure is like:

Root: HomePage
Page1 extends HomePage
Page2 extends HomePage
Page3 extends HomePage

The pages wrap the content and its own navigation. They get init in HomePage.html with wicket child.

Now, when I define a new Panel for Page1, I have to define a link for it as well. For the link onClick() I set the panel to which it refers to visible and all other panels to invisible. Also I have to define on the Page1 the panel, which gets shown when I navigate to Page1. All other panels are invisible.

Is this a good attempt or is there a better way? Now I initialize ever panel and just hold them invisible.

1
Not sure I understand what you try to archive. You a few pages wich derive from a basepage. What are the panels and why do you have to switch visibility? Are these panels on all pages? - bert
I guess I get the idea, but some relevant code would clear all ambiguities. - rotsch
Like I said to jbrookover answer. I just wanted to see some attempts of other users how they implement their ui, because I wasnt sure about my attempt. - user1090145

1 Answers

2
votes

A shot at answering your questions... This assumes you're using Wicket 1.4.x.

First, you can have many levels of Page classes, often mimicking the overlap of the design and function. For example, say you have an application where people "Write", "Browse" and "Read" user-created books.

RootPage - common headers/footers, javascript imports
AbstractWritePage extends RootPage - for anything regarding authoring
AbstractBrowsePage extends RootPage - browsing
AbstractReadPage extends ReadPage - reading

Then, I implement something like:

FullLibraryPage extends AbstractBrowsePage
FilterSearchPage extends AbstractBrowsePage

In the long run, it gets complicated, but very powerful.

Secondly, your Panel components that go visible/invisible. If you're using Wicket 1.4.x, you should look at the overrideable method onConfigure() for each Panel. In this panel, you can set the visibility like:

@Override
protected void onConfigure() {
    super.onConfigure();
    setVisible(!navTriggered);

}

where navTriggered is a boolean value residing in the containing page. Then, your link could do a simple:

@Override
protected void onClick(AjaxRequestTarget target) {
    navTriggered = false;
    target.addComponent(/* Appropriate panels; see below for multiples */);
}

The advantage to this is that you can have multiple panels triggered by the same boolean variable. There is nothing wrong with creating all of your panels at page creation time, even if they start out invisible.

Finally, if you have a lot of panels that need to be changed/triggered/etc, consider pairing an IVisitor with a marking interface. Something like...

public class Panel1 implements MyPanelGroup { ... }
public class Panel2 implements MyPanelGroup { ... }

Then, you can use an IVisitor to visit every instance of MyPanelGroup in a page and do something with visibility (either set visibility, add it to the AjaxRequestTarget, etc).

Hope that answers something :)