使标签检票口不可见

Bes*_*est 1 java label wicket

我试图隐藏标签如下:

  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);

  ..
Run Code Online (Sandbox Code Playgroud)

但标签仍然出现.有谁知道为什么?

mag*_*omi 5

您应该覆盖标签的isVisible方法.

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

  • 如果您正在使用Wicket 1.4.x,请覆盖`onConfigure()`方法并执行标准的`this.setVisible(!hide)`.这在不同的地方推荐,但在JavaDoc中没有(如果我记得的话). (4认同)
  • 正如旁注:isVisible()方法在渲染过程中可能会被调用几次.没有昂贵的计算/打击数据库应该在那里完成.Wicket 1.5为此引入了一种新方法,只需调用一次. (3认同)
  • @magomi它的技术是否也适用于wicket中的其他组件?像textarea,文本框,按钮等的东西 (2认同)