How to display tooltip (title) of option text in Tapestry 5.3.6 palette component upon mouseover?

StackOverflow https://stackoverflow.com/questions/17550859

문제

Is it possible in Tapestry 5.3.6 display tooltip (title) in palette component if the option text is too long to be displayed? I am interested in cases where option texts are almost identical, but they differ in last characters which are not visible.

도움이 되었습니까?

해결책

You just need to add custom attribute(title) to select model options. To do this you need to add your own OptionModel implementation:

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

And the last thing is to attach select model to palette:

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);
}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top