vaadin CalendarExample Context Menu

Hi,

I am new in vaadin 7.1.9. I want to create a calendar component. I used the example code from vaadin book (CalendarExample-Context Menu).

the development environment: eclipse kapler
build managment: maven 2

the calendar is created. but when I want to add a new event by right mouse click I get the following error message:

Jan 9, 2014 10:38:08 AM com.vaadin.server.DefaultErrorHandler doDefault
SEVERE:
com.vaadin.server.ServerRpcManager$RpcInvocationException: Unable to invoke method actionOnEmptyCell in com.vaadin.shared.ui.calendar.CalendarServerRpc
at com.vaadin.server.ServerRpcManager.applyInvocation(ServerRpcManager.java:170)
at com.vaadin.server.ServerRpcManager.applyInvocation(ServerRpcManager.java:118)
at com.vaadin.server.communication.ServerRpcHandler.handleBurst(ServerRpcHandler.java:207)
at com.vaadin.server.communication.ServerRpcHandler.handleRpc(ServerRpcHandler.java:111)
at com.vaadin.server.communication.UidlRequestHandler.synchronizedHandleRequest(UidlRequestHandler.java:91)
at com.vaadin.server.SynchronizedRequestHandler.handleRequest(SynchronizedRequestHandler.java:37)
at com.vaadin.server.VaadinService.handleRequest(VaadinService.java:1382)
at com.vaadin.server.VaadinServlet.service(VaadinServlet.java:238)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:304)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:240)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:164)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:462)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:164)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:562)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:395)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:250)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:188)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:302)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:895)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:918)
at java.lang.Thread.run(Thread.java:662)
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at com.vaadin.server.ServerRpcManager.applyInvocation(ServerRpcManager.java:168)
… 24 more
Caused by: java.lang.ClassCastException: com.vaadin.ui.Calendar$CalendarServerRpcImpl cannot be cast to com.vaadin.ui.Calendar
at ch.hirslanden.itrad.windows.CalenderWindow$1.handleAction(CalenderWindow.java:75)
at com.vaadin.ui.Calendar$CalendarServerRpcImpl.actionOnEmptyCell(Calendar.java:1827)
… 29 more


@Override
public void handleAction(Action action, Object sender, Object target) {
// The sender is the Calendar object

			System.out.println("Sender Objekt: " + sender.getClass().getCanonicalName());

//here is the classCastExeption
Calendar calendar = (Calendar) sender;

			if (action == addEventAction) {
				// Check that the click was not done on an event
				if (target instanceof Date) {
					Date date = (Date) target;
					// Add an event from now to plus one hour
					GregorianCalendar start = new GregorianCalendar();
					start.setTime(date);
					GregorianCalendar end = new GregorianCalendar();
					end.setTime(date);
					end.add(java.util.Calendar.HOUR, 1);
					calendar.addEvent(new BasicEvent("Calendar study", "Learning how to use Vaadin Calendar", start.getTime(), end.getTime()));
				} else
					Notification.show("No event to delete");
			} else if (action == deleteEventAction) {
				// Check if the action was clicked on top of an event
				if (target instanceof CalendarEvent) {
					CalendarEvent event = (CalendarEvent) target;
					calendar.removeEvent(event);
				} else
					Notification.show("No event to delete");
			}

		}
	};

Thanks

can someone help me please

Hi all,

I’m supporting my colleague to solve this problem and I already had a look at his code snippet. Also, I checked his implementation against your vaadin calendar example (http://demo.vaadin.com/book-examples-vaadin7/book#calendar.contextmenu). As he posted the problem days ago the code crashed while casting a class at runtime.

My colleague got a phone call from someone of you today afternoon (Jan, 13th - around 11:55am) and I assume it was about this problem. Unfortunately he was not at his work place at that time.

We know that the example code is still under work, but may we ask you whether you have a fixing or not? We need an
appropriate calendar solution asap. We already tried to get in touch with your office today. Please, could your call us again or
get in touch with us by mail: amiri.win@gmail.com. In case you prefer a phone call from our side, then please just let us know the date and time.

We are looking forward to hearing from you again.

Thanks & best regards,
Kris

Based on a quick look at the stack trace and your method, it is clear that the sender is not the Calendar but a CalendarServerRpcImpl instance. This is confirmed by taking a look at Calendar$CalendarServerRpcImpl.actionOnEmptyCell(…). This is also the case when the action handler is called by actionOnEvent(…).

Unfortunately, the sender parameter value is not very useful in this case as the nested class CalendarServerRpcImpl is private. It would contain the information about the containing Calendar instance, but it is hard to get hold of for the previously mentioned reason. You might want to use separate handler instances for separate Calendars and keep track of the calendar there until the issue is resolved.

I created a ticket to give the calendar instance as the sender (
#13191
).

I have no information on who from our side might have been in contact with you, and I’m not aware of an active support contract. Do you have an open support ticket?

I deleted the line:

Calendar calendar = (Calendar) sender;

that works fine

the sender object is the same calander object in my class.

unnecessary casting

Hi Hesam
What do you mean that your sender object is the same calendar object ?
How did you solve this issue?
Thanks

Hi Sina,

the Type of Sender Object is com.vaadin.ui.Calendar

I hope it helps you