3

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.

MartinC
  • 546
  • 11
  • 26

1 Answers1

2

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);
}
sody
  • 3,731
  • 1
  • 23
  • 28
  • thank you sody, I will try it as soon as I have time and let you know – MartinC Jul 11 '13 at 07:28
  • hm, first attempt failed when rendering the page with exception: Class SegmentCustomModel has been transformed and may not be directly instantiated. I'll investigate. – MartinC Jul 11 '13 at 14:00
  • ups, I just had to move my model class to other package, not the tapestry reserved one. THANKS! – MartinC Jul 11 '13 at 14:04