ahhh. doesn´t wicket offer a great model of programming webpages? isn´t it too easy to do things like this?
add(new ListView("mylist",someList){
@Override
protected void populateItem(ListItem item){
item.add(new PageLink("deleteThisEntry",new DeletePage(item.getModel())));
}};
});
but wait, PageLink(Page) is deprecated:
/**
* This constructor is ideal if a Page object was passed in from a previous Page. Construct a
* link to the Page. Warning: DO NOT use this for constructing links to pages you didn't already
* have an instance of. This constructor is strongly discouraged for anything other than linking
* back to the same page.
*
* @param id
* See component
* @param page
* The page
* @deprecated rather than using this class/ constructor, use normal {@link Link links} and call
* setResponsePage in their {@link Link#onClick() onClick} methods.
*/
@Deprecated
public PageLink(final String id, final Page<?> page)
why is that? if you look at it, it is very obvious. because it is not lazy. that means that you´re creating a big bunch of pages without needing them and all of them need to be serialized, maybe replicated etc.
it gets worse: when not reusing listitems, you´ll do that on every rendering of the example code!
even more worse, if your fellow programmer did something funny like:
@SomeFunkyAnnotationForInterception
class DeletePage extends WebPage{
public DeletePage(IModel objectToDelete){
deleteObject(objectToDelete.getObject());
setResponsePage(DeletionDonePage.class);
}
}
which at least could be a valid usecase.
so please, please, please - with sugar on top - replace
new PageLink(id,new XYPage(...))
by
new Link(id){
public void onClick(){
setResponsePage(new XYPage(...));
}
}
in order to create the page only when needed.