Java 如何在鼠标悬停时显示Tapestry 5.3.6调色板组件中选项文本的工具提示(标题)?

Java 如何在鼠标悬停时显示Tapestry 5.3.6调色板组件中选项文本的工具提示(标题)?,java,javascript,title,tapestry,palette,Java,Javascript,Title,Tapestry,Palette,如果选项文本太长而无法显示,Tapestry 5.3.6是否可以在调色板组件中显示工具提示(标题)?我对选项文本几乎相同,但在最后一个不可见的字符上不同的情况很感兴趣。您只需要添加自定义属性(title)来选择模型选项。为此,您需要添加自己的选项model实现: public class CustomOptionModel implements OptionModel { private final String label; private final Object value

如果选项文本太长而无法显示,Tapestry 5.3.6是否可以在调色板组件中显示工具提示(标题)?我对选项文本几乎相同,但在最后一个不可见的字符上不同的情况很感兴趣。

您只需要添加自定义属性(
title
)来选择模型选项。为此,您需要添加自己的
选项model
实现:

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类CustomOptionModel实现OptionModel{
私有最终字符串标签;
私人最终目的价值;
私有最终地图属性;
公共CustomOptionModel(最终字符串标签,
最终对象值,
最终字符串(工具提示){
this.label=标签;
这个值=值;
如果(工具提示!=null){
attributes=newhashmap();
属性。放置(“标题”,工具提示);
}否则{
属性=null;
}
}
公共字符串getLabel(){
退货标签;
}
公共布尔值已禁用(){
返回false;
}
公共映射getAttributes(){
返回属性;
}
公共对象getValue(){
返回值;
}
}
最后一件事是将“选择模型”附加到选项板:

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);
}
public SelectModel getMySelectModel(){
最终列表选项=新建ArrayList();
选项。添加(新的CustomOptionModel(“第一”,1,“第一项”));
添加(新的CustomOptionModel(“第二项”,2,“第二项”);
添加(新的CustomOptionModel(“第三项”,3,“第三项”);
返回新的SelectModelImpl(空,选项);
}

谢谢你,sody,我会在有时间后尽快尝试,并让你知道,嗯,呈现页面时第一次尝试失败,出现异常:类SegmentCustomModel已转换,可能无法直接实例化。我将调查.ups,我只需要将我的模型类移动到另一个包,而不是tapestry保留的包。谢谢