如果选项文本太长而无法显示,是否可以在Tapestry 5.3.6中显示调色板组件中的工具提示(标题)?我对选项文本几乎相同的情况感兴趣,但它们在最后一个不可见的字符中有所不同。
答案 0 :(得分:2)
您只需添加自定义属性(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);
}