Urgent Help with Calendar component....

Im already ask this before, but didnt get any answer, and need to realese the application this Monday, but I have the next problem:

Sometimes when I add a new event, the event is not show on the calendar component when Im on view mode Day, but if I click on the Week mode there it is, and only on some days of the week, mainly with Fridays, or Mondays.

For what Im suspecting is because the locale on the component is not right, event if I set the component widgetCalendar.setLocale(new Locale(“en”,“US”)), is mixing the first day of week and last day of the week. Im already check my server configuration, my aplication configuration, I dont know what is wrong:

here is my code:

this.widgetCalendar.setLocale(Locale.US);
this.widgetCalendar.setStartDate(startDay);
this.widgetCalendar.setEndDate(endDay);
this.widgetCalendar.setTimeFormat(Calendar.TimeFormat.Format24H);
this.widgetCalendar.setWidth("95%");
this.widgetCalendar.setHeight("95%");
this.widgetCalendar.setVisible(true);
this.widgetCalendar.setWeeklyCaptionFormat("dd MMM");
this.setFirstVisibleHourOfDay(getCalendarStartTime());
this.setLastVisibleHourOfDay(getCalendarEndTime());
//this.widgetCalendar.setFirstVisibleDayOfWeek(1);
//this.widgetCalendar.setLastVisibleDayOfWeek(7);
// this.widgetCalendar.setReadOnly(false);

[handlers code here]

here I add a new event:

public void addEvent(BasicEvent event)
{
if (this.currentNewEvent != null)
{
container.removeItem(this.currentNewEvent);
}
OklexBasicEvent newEvent = new OklexBasicEvent(event.getCaption(), event.getDescription(), event.getStart(), event.getEnd(), true);
Logger.Log("OKWCalendar","addEvent","setting new event:" + newEvent.getCaption());
this.currentNewEvent = newEvent;
Logger.Log("OKWCalendar","addEvent","adding event to container..." );
container.addBean(this.currentNewEvent);
if(!isEventValid(currentNewEvent)){
Logger.Log("OKWCalendar","addEvent","event has an error..." );
currentNewEvent.setStyleName("error");
}
widgetCalendar.markAsDirtyRecursive();
this.btnSave.setVisible(true);
}

22403.png
22404.png

Still dont have an answer for this, I dont know if the problem is with the Vaadin Calendar or is something I did wrong, somebody else have this issue? I have checked the documentation twice and the forum and found nothing…

Hi Jose,

Never had this kind of troubles, still using Calendar component in several applications.

  • Did you try without any “customization” on the calendar object ?
  • What’s the values inside :
    this.setFirstVisibleHourOfDay(getCalendarStartTime());
    this.setLastVisibleHourOfDay(getCalendarEndTime());
  • Do you have filters in your container ?

Which version are you running on ?

Regards

Hi Sebastien, thanks for asking, no I dont have any filter on the calendar, but the ‘costumization’ of the calendar is on the DB there I save a ‘type’ of calendar ( 1 for Monday to Friday, 2 for Monday to Saturday and 3 for Monday to Sunday ) but this was given me some problems so for now I left that out, also on the db is the start time and end time for each calendar the ‘getCalendarStartTime()’ and ‘getCalendarEndTime()’ that right now is start at 7 (am) and ends at 23 (11:00 pm).

The component follows this steps:

  1. From a combobox select the calendar ( I manage diferents calendars)
  2. get the ‘costumization’ of the calendar from the db and load the calendar. (first part of the code)
  3. get the events for that calendar from the db.
  4. load those events on the calendar. (btw the old events also show correctly on the day view, the problem is when is a new event.)
ArrayList<OKCalendarEvent> events = new ArrayList<>();
container.removeAllItems();
events.addAll(
              OKCalendarEventData.listAllEventsByCalendarBetween(getInnerCalendar().getCalendar_id(),
                         new Timestamp(from.getTimeInMillis()),
                         new Timestamp(to.getTimeInMillis()),
                         CurrentUser.getCurrentToken().getDataSource()));

for (OKCalendarEvent e : events) {
OklexBasicEvent event = new OklexBasicEvent(e.getName(),
                                            e.getDescription(),
                                            e.getStart(),
                                            e.getEnd(),
                                            false);
container.addBean(event);
}

if(currentNewEvent != null){
     container.addBean(currentNewEvent);
         if(!isEventValid(currentNewEvent)){
               currentNewEvent.setStyleName("error");
 }

this.btnSave.setVisible(true); }

vaadinCalendar.markAsDirtyRecursive();
  1. Add the new event on the calendar.

OklexBasicEvent is an extension of BasicEvent, I only added a boolean field to check if is new or already on the db.
public OklexBasicEvent(String name, String description, Date start, Date end, boolean newEvent ){
super(name, description, start, end);
setNewEvent(newEvent);
}

Still no answer? or any ideas?? I’m getting in problems with my client here… :S Im thinking on doing my own component, very very simple way to suply this component.

Well if somebody has the same problem, I think I just fixed, but I still dont see the problem of why…

So, the problem was that I was using the BeanItemContainer, to add the events to the calendar, instead of a BasicEventProvider, just changed that part, so my new question is; why the beanItemContainer.addBean(new MyEvent()) dosen’t work like the basicEventProvider.addEvent(new MyEvent())?, On the documentation I can see that both methods are valid, and didn’t read any warning that this kind of erros could happend. So I hope someone can explain me that.

Hi,


Book of Vaadin
says:


“The container must be ordered by the start time. You have to sort the BeanItemContainer every time after you have added or modified events”

Did you order the container as suggested?

Hello Alejandro, thanks for answering. Looks like I haven’t try that, I will check it out, but using a BasicEventPovider class solved most of my issues, for now…