Use HTML in caption and description of calender items

Hello,

is there a possibility to use HTML in the caption and description of calendar items?

2020-04-24 08_03_24-aPSU

Greetings
Andreas

Hello @Andreas.Brueck!

For html caption, you can use the following code:

@Inject
protected Calendar<Date> calendar;

@Subscribe
protected void onInit(InitEvent event) {
    com.vaadin.v7.ui.Calendar vCalendar = calendar.unwrap(com.vaadin.v7.ui.Calendar.class);
    vCalendar.setEventCaptionAsHtml(true);
}

The CUBA platform and Vaadin do not have special methods to display event descriptions as an HTML. You need to follow a few steps to solve the problem:

  1. Create web-toolkit Module
  2. Create SampleCalendarConnector class in web.toolkit.ui.client. package and override getTooltipInfo method of CubaCalendarConnector class:
package com.company.sample.web.toolkit.ui.client;

import com.google.gwt.dom.client.Element;
import com.haulmont.cuba.web.widgets.CubaCalendar;
import com.haulmont.cuba.web.widgets.client.calendar.CubaCalendarConnector;
import com.vaadin.client.TooltipInfo;
import com.vaadin.shared.ui.Connect;
import com.vaadin.shared.ui.ContentMode;

@Connect(value = CubaCalendar.class, loadStyle = Connect.LoadStyle.LAZY)
public class SampleCalendarConnector extends CubaCalendarConnector {

    @Override
    public TooltipInfo getTooltipInfo(Element element) {
        TooltipInfo tooltipInfo = super.getTooltipInfo(element);
        tooltipInfo.setContentMode(ContentMode.HTML);
        return tooltipInfo;
    }
}
  1. Replace CubaCalendarConnector with SampleCalendarConnector in AppWidgetSet.gwt.xml file:
<?xml version="1.0" encoding="UTF-8"?>
<module>

    <inherits name="com.haulmont.cuba.web.widgets.WidgetSet"/>

    <replace-with class="com.company.sample.web.toolkit.ui.client.SampleCalendarConnector">
        <when-type-is class="com.haulmont.cuba.web.widgets.client.calendar.CubaCalendarConnector"/>
    </replace-with>
</module>

Regards,
Gleb

Hi @durygin,

sorry for my late reply. Your solution runs perfectly:

image

Thx :slight_smile:
Andreas

1 Like