...
Code Block | ||||
---|---|---|---|---|
| ||||
<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml" xmlns:wicket="http://wicket.apache.org/" xml:lang="en" lang="en"> |
Do's and dont (thanks orange11-blog)
Do use models
Don't do this
Code Block |
---|
public IncomePanel(String id, Person person) {
super(id);
add(new Label("salary", person.getSalary()); // no model!
}
|
But this -
Code Block |
---|
public IncomePanel(String id, IModel<Person> personModel) {
super(id,personModel);
add(new Label("salary", new PropertyModel(personModel, "salary"));
}
|
Or even this:
Code Block |
---|
public IncomePanel(String id, IModel<Person> personModel) {
super(id, new CompoundPropertyModel(personModel);
add(new Label("salary");
}
|
Why - because A) we don't want to risk serialize an object, models are lightweight and ok. And we want to let the component take care of the detach when the request is done B) With an direct-entity we would set an nondynamic value. With a model, the label will update the value from the entity it's using.
Don't use an Ajax library without intimate knowledge of the library
May collide with wicket code, make sure your JS-library well
Do make sure you understand the repeaters for high performance sites
Wicket by default provides the following repeater: Loop, ListView, RepeatingView, RefreshingView, DataTable. This list is not even exhaustive; there are some more variations. Every repeater constructs a transient component for each iteration: the loop item. Every loop item has a Wicket model to look up the item's data.
Here are some points to consider to choose the most optimal repeater:
- Moment of data retrieval. Is it during construction only, or for each render again?
- During a re-render, is all data retrieved at once or one by one?
- Moment the loop-item's model is created. First time only, or again for each render, or does it retain existing models and only add/remove models as the underlying data changes (ItemReusePolicy)?
- Can you control the model creation?
- Is pagination/sorting needed?
Don't overuse inheritance - use composition
Do keep markup in sync with the component code
Don't try to do authorization from a servlet filter
Do take your time to override key Wicket features
Wicket Filter Mapping
Wicket 1.4.x and upwards {}
On these versions, you should prefer to use WicketFilter instead of WicketServlet. If you want, it's possible to map /*
instead of /app/*
. But remember to configure the ignorePaths
parameter to ignore static resources and leave them to be handled by the container.
Ignoring paths
If you want to leave static resources to be handled by the container, configure the ignorePaths
init parameter as follows:
...