Hi

Yes there'll always be some repetition. Depending on your logic you might also stuff the first block in the onClick event to generate the model if it's not used anywhere else. That could eliminate the first block.

The problem about reusable components in wicket is that probably you might end up with some problems when using the same component instance on two pages unless you re-instantiate your Commons class in every call which might in turn produce a lot of overhead if you only need a few of those labels and stuff. What you could also du is writing a kind of factory method in a base page class (I always have a BasePage class all my pages extend from with some common functionality). There you could have a method like
protected Label getIdLabel(String value) { return new Label("id", value); }

Matt

cmoulliard wrote:
Mattias,

OK about what you propose but we repeat the test a second time so the code
still remains very verbose.
Thanks for the suggestion.

I think that this is a general remark that some users make about Wicket. It
is very difficult to reuse part of the code.

Here is another example :

I have a label called id which is used in different page. The way proposes
by Wicket to code it is
Page Request

item.add(new Label("id", String.valueOf(request.getId())));

Page Notification

item.add(new Label("id", String.valueOf(notification.getId())));

When we compare page request and page notification, we see that we repeat
the same code two times.

It could be interesting to set the value of the label in the page and to
declare it separately

e.g

public class Commons {

        public static Label labelId = new Label("id");
        ...
}


Page Request

item.add( labelId.setValue( String.valueOf(request.getId()) );

Page Notification

item.add( labelId.setValue( String.valueOf(notification.getId()) );

Regards,

Charles

Attachment: smime.p7s
Description: S/MIME Cryptographic Signature

Reply via email to