java如何在ZK中定制组件标签
我需要帮助,我想自定义zk中的标签组件,我需要添加一个属性,当我设置mandatory=“true”时,asterix符号将出现,如果我设置mandatory=“false”,asterix符号将消失,我正在这样尝试:
private Label label;
private Label sign;
private String lblValue;
private String REQUIRED_SIGN = " *";
private boolean mandatory;
public SignLabelCustom()
{
label = new Label();
label.setSclass("form-label");
appendChild(label);
sign = new Label();
if(mandatory=true){
sign.setValue(REQUIRED_SIGN);
sign.setStyle("color: red");
appendChild(sign);
}
else{
sign.setValue("");
sign.setStyle("color: red");
removeChild(sign);
}
}
public String getValue() {
return lblValue;
}
public boolean isMandatory() {
return mandatory;
}
public void setMandatory(boolean mandatory) {
this.mandatory = mandatory;
}
public void setValue(String lblValue) {
label.setValue(lblValue);
this.lblValue = lblValue;
}
但是这种情况不起作用,怎么解决呢
# 1 楼答案
你可能想要的是HtmlMacroComponent,它结合了标签和文本框
从zul文件开始:
。。。并为其创建一个组件
。。。现在你可以使用它,比如在zul文件的顶部定义它。。。(根据需要调整包装和.zul名称):
。。。所以你可以简单地使用它
以后你可以为它定义一个语言插件
我的语言插件 xul/html 我的文本框 通用域名格式。实例我的文本框 /zk/textbox。祖尔
。。。这样你就不需要把定义放在每个。zul文件,你再也不用它了。有关这方面的更多信息,请参见documentation
当然,你也只能创建一个新标签,等等。但我发现为那些结合了各种组件的工作创建宏组件是一个好主意,因为这样,例如,你也可以自动添加验证等等