It's the same reason you shouldn't use new Label("id"
object.getSomeText());.  See this example:

public MyPage () {
  Person p = getPersonFromSomewhere();
  Label l = new Label("numberOfPhoneNumbers", p.getPhoneNumbers().size());
  l.setVisible(p.getPhoneNumbers().size() > 0);
  new Link("addPhoneNumber") {
    onClick() {
      p.addPhoneNumber("123-456-7890");
    }
  }
}

When you add the phone number, it would not show up.  Not only would your
label not be able to get the new value for the size of the phone numbers,
but it would also not change it's visibility.  Why?  Because you statically
set both of those in the constructor.  They can't change unless you go to a
completely new instance of the page.  But clicking that link (or performing
some ajax operation) won't create a new page - they'll use the one you're
already on.

Synopsis: You should use models and override isVisible because they always
retrieve the latest information for every render.

--
Jeremy Thomerson
http://www.wickettraining.com



On Tue, Sep 22, 2009 at 8:18 AM, Nicolas Melendez <nmelen...@getsense.com.ar
> wrote:

> Jeremy:you say "2 - don't call setEnabled() - override isEnabled"
>
> why is better override isEnable then setEnable?
>
> thanks NM
>
> On Mon, Sep 21, 2009 at 9:44 AM, cmoulliard <cmoulli...@gmail.com> wrote:
>
> >
> > Joseph,
> >
> > Can you explain a little bit what you mean by provide it with attribute
> > (IModel<String>) ?
> >
> >        private Label labelTitle;
> >        public static Label createLabelTitle(String title) {
> >                 return new Label("title",new Model( title ));
> >        }
> >
> > --> becomes
> >
> >        private Label labelTitle;
> >        public static Label createLabelTitle(String title) {
> >                return new Label(title,new PropertyModel( ModelClass,
> title
> > ));
> >        }
> >
> > Is it right what I create ?
> >
> >
> > Joseph Pachod wrote:
> > >
> > > cmoulliard wrote:
> > >> What I have done to avoid to repeat the creation of the labels is to
> > >> define
> > >> and use static method
> > >>
> > >>      private Label labelTitle;
> > >>      public static Label getLabelTitle(String title) {
> > >>              return new Label("title",new Model( title ));
> > >>      }
> > >>
> > > I personally would name this method createLabelTitle(String title) or
> > > getNewLabelTitle(String title), for explicitness.
> > >
> > > Furthermore, I would directly provide it with a "final IModel<String>
> > > title" attribute, not to dictate how the data has to be provided
> > > (dynamic or not for example).
> > >
> > > In the end, this method is fine for just a label, but for anything more
> > > complex a panel would be the way to go I would say. The main exception
> > > here I see right now is the case of pages.
> > >
> > > For example, if we're speaking of a page title, then I would define it
> > > in my base page and make an abstract String getTitle() method in the
> > > base page so I'm sure everyone set it up later on. I would do the same
> > > if it's a specific kind of structured page, for example an abstract
> > > class ContentHoldingPage extend TheBasePage.
> > >
> > > ++
> > >
> > > ---------------------------------------------------------------------
> > > To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
> > > For additional commands, e-mail: users-h...@wicket.apache.org
> > >
> > >
> > >
> >
> >
> > -----
> > Charles Moulliard
> > SOA Architect
> >
> > My Blog :  http://cmoulliard.blogspot.com/
> http://cmoulliard.blogspot.com/
> > --
> > View this message in context:
> >
> http://www.nabble.com/Is-it-the-best-way-to-code-a-Link-depending-on-a-condition-tp25488603p25530206.html
> > Sent from the Wicket - User mailing list archive at Nabble.com.
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
> > For additional commands, e-mail: users-h...@wicket.apache.org
> >
> >
>

Reply via email to