Revision history [back]

click to hide/show revision 1
initial version

asked 2015-03-02 06:53:58 +0800

Senthilchettyin gravatar image Senthilchettyin flag of India

http://emrpms.blogspot.in...

Problem in setting custom title for Calender Event with own dateformatter

Hello.

For ZK Calender, I am using my own date formatter as describe here.

And also, i have customized title for each calender event. The problem is if i am not using the own date formatter, then title of the each calender event shown correctly.

But when i use my own calender event, the customized title (getTitle from class that implements CalenderEvent) does not shown and the value from the date formatter is showing.

I think ZK Using the method getCaptionByTimeOfDay both for the caption for the left side of the calender and each calender event. Actually it should affect the left side of the calender , not the title of the each calender event.

Is this bug ?

        calendarCtrl.setDateFormatter(new MyCalenderDateFormat());
    package com.product.webapp.appt;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Locale;
import java.util.TimeZone;

import org.zkoss.calendar.api.DateFormatter;

public class MyCalenderDateFormat implements DateFormatter {

    private String _dayFormat = "EEE MM/d";
    private String _weekFormat = "EEE";
    private String _timeFormat = "hh:mm a";
    private String _ppFormat = "EEE, MMM/d";
    private SimpleDateFormat _df, _wf, _tf, _pf;

    public String getCaptionByDate(Date date, Locale locale, TimeZone timezone) {
        if (_df == null) {
            _df = new SimpleDateFormat(_dayFormat, locale);
        }
        _df.setTimeZone(timezone);

        return _df.format(date);
    }

    public String getCaptionByDateOfMonth(Date date, Locale locale,
            TimeZone timezone) {
        Calendar cal = Calendar.getInstance(timezone, locale);
        cal.setTime(date);
        if (cal.get(Calendar.DAY_OF_MONTH) == 1) {
            SimpleDateFormat sd = new SimpleDateFormat("MMM d", locale);
            sd.setTimeZone(timezone);
            return sd.format(date);
        }
        return Integer.toString(cal.get(Calendar.DAY_OF_MONTH));
    }

    public String getCaptionByDayOfWeek(Date date, Locale locale,
            TimeZone timezone) {
        if (_wf == null) {
            _wf = new SimpleDateFormat(_weekFormat, locale);
        }
        _wf.setTimeZone(timezone);
        return _wf.format(date);
    }

    public String getCaptionByTimeOfDay(Date date, Locale locale,
            TimeZone timezone) {
        if (_tf == null) {
            _tf = new SimpleDateFormat(_timeFormat, locale);
        }
        _tf.setTimeZone(timezone);

        return _tf.format(date);
    }

    public String getCaptionByPopup(Date date, Locale locale, TimeZone timezone) {
        if (_pf == null) {
            _pf = new SimpleDateFormat(_ppFormat, locale);
        }
        _pf.setTimeZone(timezone);

        return _pf.format(date);
    }

    public String getCaptionByWeekOfYear(Date date, Locale locale,
            TimeZone timezone) {
        Calendar cal = Calendar.getInstance(timezone, locale);
        cal.setTime(date);
        return String.valueOf(cal.get(Calendar.WEEK_OF_YEAR));
    }
}

If i comment the own date formatter, You can see the title as shown in the picture.

image description

If i use the own dateformatter, then customized title gone and default title are shown as shown here

image description

Problem in setting custom title for Calender Event with own dateformatter

Hello.

For ZK Calender, I am using my own date formatter as describe here.

And also, i have customized title for each calender event. The problem is if i am not using the own date formatter, then title of the each calender event shown correctly.

But when i use my own calender event, the customized title (getTitle from class that implements CalenderEvent) does not shown and the value from the date formatter is showing.

I think ZK Using the method getCaptionByTimeOfDay both for the caption for the left side of the calender and each calender event. Actually it should affect the left side of the calender , not the title of the each calender event.

Is this bug ?

        calendarCtrl.setDateFormatter(new MyCalenderDateFormat());
    package com.product.webapp.appt;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Locale;
import java.util.TimeZone;

import org.zkoss.calendar.api.DateFormatter;

public class MyCalenderDateFormat implements DateFormatter {

    private String _dayFormat = "EEE MM/d";
    private String _weekFormat = "EEE";
    private String _timeFormat = "hh:mm a";
    private String _ppFormat = "EEE, MMM/d";
    private SimpleDateFormat _df, _wf, _tf, _pf;

    public String getCaptionByDate(Date date, Locale locale, TimeZone timezone) {
        if (_df == null) {
            _df = new SimpleDateFormat(_dayFormat, locale);
        }
        _df.setTimeZone(timezone);

        return _df.format(date);
    }

    public String getCaptionByDateOfMonth(Date date, Locale locale,
            TimeZone timezone) {
        Calendar cal = Calendar.getInstance(timezone, locale);
        cal.setTime(date);
        if (cal.get(Calendar.DAY_OF_MONTH) == 1) {
            SimpleDateFormat sd = new SimpleDateFormat("MMM d", locale);
            sd.setTimeZone(timezone);
            return sd.format(date);
        }
        return Integer.toString(cal.get(Calendar.DAY_OF_MONTH));
    }

    public String getCaptionByDayOfWeek(Date date, Locale locale,
            TimeZone timezone) {
        if (_wf == null) {
            _wf = new SimpleDateFormat(_weekFormat, locale);
        }
        _wf.setTimeZone(timezone);
        return _wf.format(date);
    }

    public String getCaptionByTimeOfDay(Date date, Locale locale,
            TimeZone timezone) {
        if (_tf == null) {
            _tf = new SimpleDateFormat(_timeFormat, locale);
        }
        _tf.setTimeZone(timezone);

        return _tf.format(date);
    }

    public String getCaptionByPopup(Date date, Locale locale, TimeZone timezone) {
        if (_pf == null) {
            _pf = new SimpleDateFormat(_ppFormat, locale);
        }
        _pf.setTimeZone(timezone);

        return _pf.format(date);
    }

    public String getCaptionByWeekOfYear(Date date, Locale locale,
            TimeZone timezone) {
        Calendar cal = Calendar.getInstance(timezone, locale);
        cal.setTime(date);
        return String.valueOf(cal.get(Calendar.WEEK_OF_YEAR));
    }
}

If i comment the own date formatter, You can see the title as shown in the picture.

image descriptionimage description

If i use the own dateformatter, then customized title gone and default title are shown as shown here

image descriptionimage description

Problem in setting custom title for Calender Event with own dateformatter

Hello.

For ZK Calender, I am using my own date formatter as describe here.

And also, i have customized title for each calender event. The problem is if i am not using the own date formatter, then title of the each calender event shown correctly.

But when i use my own calender event, the customized title (getTitle from class that implements CalenderEvent) does not shown and the value from the date formatter is showing.

I think ZK Using the method getCaptionByTimeOfDay both for the caption for the left side of the calender and each calender event. Actually it should affect the left side of the calender , not the title of the each calender event.

Is this bug ?

        calendarCtrl.setDateFormatter(new MyCalenderDateFormat());
    package com.product.webapp.appt;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Locale;
import java.util.TimeZone;

import org.zkoss.calendar.api.DateFormatter;

public class MyCalenderDateFormat implements DateFormatter {

    private String _dayFormat = "EEE MM/d";
    private String _weekFormat = "EEE";
    private String _timeFormat = "hh:mm a";
    private String _ppFormat = "EEE, MMM/d";
    private SimpleDateFormat _df, _wf, _tf, _pf;

    public String getCaptionByDate(Date date, Locale locale, TimeZone timezone) {
        if (_df == null) {
            _df = new SimpleDateFormat(_dayFormat, locale);
        }
        _df.setTimeZone(timezone);

        return _df.format(date);
    }

    public String getCaptionByDateOfMonth(Date date, Locale locale,
            TimeZone timezone) {
        Calendar cal = Calendar.getInstance(timezone, locale);
        cal.setTime(date);
        if (cal.get(Calendar.DAY_OF_MONTH) == 1) {
            SimpleDateFormat sd = new SimpleDateFormat("MMM d", locale);
            sd.setTimeZone(timezone);
            return sd.format(date);
        }
        return Integer.toString(cal.get(Calendar.DAY_OF_MONTH));
    }

    public String getCaptionByDayOfWeek(Date date, Locale locale,
            TimeZone timezone) {
        if (_wf == null) {
            _wf = new SimpleDateFormat(_weekFormat, locale);
        }
        _wf.setTimeZone(timezone);
        return _wf.format(date);
    }

    public String getCaptionByTimeOfDay(Date date, Locale locale,
            TimeZone timezone) {
        if (_tf == null) {
            _tf = new SimpleDateFormat(_timeFormat, locale);
        }
        _tf.setTimeZone(timezone);

        return _tf.format(date);
    }

    public String getCaptionByPopup(Date date, Locale locale, TimeZone timezone) {
        if (_pf == null) {
            _pf = new SimpleDateFormat(_ppFormat, locale);
        }
        _pf.setTimeZone(timezone);

        return _pf.format(date);
    }

    public String getCaptionByWeekOfYear(Date date, Locale locale,
            TimeZone timezone) {
        Calendar cal = Calendar.getInstance(timezone, locale);
        cal.setTime(date);
        return String.valueOf(cal.get(Calendar.WEEK_OF_YEAR));
    }
}

If i comment the own date formatter, You can see the title as shown in the picture.

image description

If i use the own dateformatter, then customized title gone and default title are shown as shown here

image description

There is another problem, if we timeslots="6", then both Title text and Content text are showing in the Title bar itself as shown here image description

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More