Dashboard > People > codesmell > 2008 > November > 06 > Pagelink considered harmful
  codesmell Log In   View a printable version of the current page.  
  Pagelink considered harmful
Added by Uwe Schaefer, last edited by Uwe Schaefer on Nov 06, 2008
Labels: 

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.

November 2008
Sun Mon Tue Wed Thu Fri Sat
            1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30            

WTF
Quartz fits

This site is powered by a free Atlassian Confluence Personal Server License. Evaluate Confluence for your organisation or read more about Confluence licensing here.
Powered by Atlassian Confluence, the Enterprise Wiki. (Version: 2.2.9 Build:#527 Sep 07, 2006) - Bug/feature request - Contact Administrators