2

I really need your help by a wicket-problem.

I want to add a tooltip to all the rows(by mouse hover) in a PropertyColumn. But how can I do it? I've seen solutions with an Abstractcolumn. But I have to use a PropertyColumn because i need the propertyExpression and don't need the sortProperty.

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Christian
  • 22,585
  • 9
  • 80
  • 106

2 Answers2

3

One way is to modify the DataTable like this:

add(new DefaultDataTable("wicektid", null, null, 10) {

    @Override
    protected Item newCellItem(String id, int index, IModel model) {
        Item item = super.newCellItem(id, index, model); 
        item.add(AttributeModifier.replace("title", "Your Title"));
        return item;
    }

    @Override
    protected Item newRowItem(String id, int index, IModel model) {
        Item item = super.newRowItem(id, index, model); 
        item.add(AttributeModifier.replace("title", "Your Title"));
        return item;
    }

});

Here you have the control if you want the tooltip on whole rows or on individual cells.

If you want to do it in certain columns you can override populateItem in the column like this:

add(new PropertyColumn<>(){

    @Override
    public void populateItem(Item<ICellPopulator<T>> item, String componentId, IModel<T> rowModel) {
        super.populateItem(item, componentId, rowModel); 
    }

});
Robert Niestroj
  • 15,299
  • 14
  • 76
  • 119
  • The second solution is the preferred one for me. For clarity, you'd add a (Tooltip)Behaviour or something to the item in the populateItem-method. – Buurman Aug 15 '13 at 06:38
  • Thanks for your answer. But i've a question: You write in the second possible solution, that I should override `newCellItem`, but you override `populateItem`. I will try this solution as fast as possible. Yesterday I also tought about something like that. Many thx. I will update my question, when I've checked if it works. :) – Christian Aug 15 '13 at 07:49
  • @RobertNiestroj is it possible to make String in AttributeModifier as multiline, I tried
    but in html it renders as <br> and it has no effect
    – eatSleepCode Jan 07 '15 at 11:49
  • @eatSleepCode: http://stackoverflow.com/questions/358874/how-can-i-use-a-carriage-return-in-a-html-tooltip – Robert Niestroj Jan 07 '15 at 14:32
  • @RobertNiestroj this link is useful but there is one problem the tool tip gets generated at runtime and I tried using character ` ` but it gets rendered as &#13; which makes it display as same problem – eatSleepCode Jan 08 '15 at 09:06
2

I now have found the solution.

First thing, which is important to know is, that in the populateItem-Method, there has to be at least one object in it. For example a label. Because you can't add a string or a tooltip to a cell without something in it. So i had to put a label in it and added the string to that label. After that i've added a PrototipBehavior to the label:

 public void populateItem(final Item cellItem, final String componentId, final IModel model) {
                Long id = ((MyObject) model.getObject()).getId();
                String desc = ((MyObject) model.getObject()).getDescription();
                Label l = new Label(componentId, id + "");
                l.add(new PrototipBehaviour(desc));
                cellItem.add(l);

            }
Christian
  • 22,585
  • 9
  • 80
  • 106