如果选项文本太长而无法显示,是否可以在Tapestry 5.3.6的调色板组件中显示工具提示(标题)?我对选项文本几乎相同但它们在看不见的最后一个字符方面有所不同的情况感兴趣。
您只需要添加自定义attribute(title
)即可选择模型选项。为此,您需要添加自己的OptionModel
实现:
public class CustomOptionModel implements OptionModel {
private final String label;
private final Object value;
private final Map<String, String> attributes;
public CustomOptionModel(final String label,
final Object value,
final String tooltip) {
this.label = label;
this.value = value;
if (tooltip != null) {
attributes = new HashMap<String, String>();
attributes.put("title", tooltip);
} else {
attributes = null;
}
}
public String getLabel() {
return label;
}
public boolean isDisabled() {
return false;
}
public Map<String, String> getAttributes() {
return attributes;
}
public Object getValue() {
return value;
}
}
最后一件事是将选择模型附加到调色板:
public SelectModel getMySelectModel() {
final List<OptionModel> options = new ArrayList<OptionModel>();
options.add(new CustomOptionModel("First", 1, "First Item"));
options.add(new CustomOptionModel("Second", 2, "Second Item"));
options.add(new CustomOptionModel("Third", 3, "Third Item"));
return new SelectModelImpl(null, options);
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句