Best
Best

Reputation: 2318

Make Label Wicket invisible

I tried to hide a label as follows :

  Form form = new Form("form");

  Label myLabel = new Label("myLabel", new ResourceModel("mylabel.text").getObject());
  if(hide == true){
        myLabel.setVisible(Boolean.FALSE);
  }
  form.add(myLabel);

  ..

but the label still appears. Does anyone know why?

Upvotes: 1

Views: 4497

Answers (3)

1ac0
1ac0

Reputation: 2939

Informations below are for Wicket 1.4 (quite old now).

For Wicket 1.5 and 6.x (aka 1.6) the right way is override component's onConfigure() and call setVisible() from there:

@Override
protected void onConfigure()
{
    super.onConfigure();
    boolean flag = myDbDAO.getVisibilityOfThisPanel()
    this.setVisible(flag);
}

Keep component.isVisible() light, it should be called more than once per request so long-computing-task there will slow page/panel loading. Put heavy process (DB, math) in onConfigure() and from there call isVisible() if needed.

Upvotes: 0

magomi
magomi

Reputation: 6685

You should override the isVisible method of your label.

Label label = new Label(...) {
  @Override
  public boolean isVisible() {
    return !hide;
  }
};
form.add(...)
...

Upvotes: 5

osdamv
osdamv

Reputation: 3583

actually you are making invisible the label, the problem is redraw the html page,what you can do it refreshing the page or with help of ajax

Upvotes: 0

Related Questions