Problems with design of @EventHandler

Gentlfolk,
here to have a winge.

I’ve just spent the morning trying to debug an @EventHandler as per:

https://vaadin.com/docs/flow/polymer-templates/tutorial-template-event-handlers.html

My event handler looks like:

	public static class Day
	{
		public DayName dayName;
	}

	@EventHandler
	private void onToggle(@ModelItem Day day)
	{

My event handler was being called as expected but when I inspected the the ‘day’ object in the debugger all of its members where null;

If I tried to write

	System.out.printlin("Day: " +day.dayName);

The then output would be

Day: null

I eventually realised that vaadin are using a proxy on the getter so that if I used:

	System.out.printlin("Day: " +day.getDayName());

I would get

Day: Monday

If I trace the call to day.getDayName() I see

com.vaadin.flow.templatemodel.InvalidTemplateModelException: au.com.noojeeit.micropbx.ui.user.views.OfficeHoursView$Day has no property named openingTime (or it has been excluded)
	at com.vaadin.flow.templatemodel.TemplateModelProxyHandler.intercept(TemplateModelProxyHandler.java:153)
	at au.com.noojeeit.micropbx.ui.user.views.OfficeHoursView.Day$.getOpeningTime(Unknown Source)
	at jdk.internal.reflect.GeneratedMethodAccessor250.invoke(Unknown Source)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:45005)
	at java.base/java.lang.reflect.Method.invoke(Method.java:566)
	at com.zeroturnaround.javarebel.gt.invokeMethod(SourceFile:282)
	at au.com.noojeeit.micropbx.ui.user.views.OfficeHoursView.onToggle(OfficeHoursView.java:180)

This has been a nightmare to debug. The documentation doesn’t mention the proxy is in use.
I managed to start off by using direct field access (day.dayName) and so fell into a can of worms that has takein me 6 hours to get out of.

So a couple of questions:

  1. is the proxy really necessary? It appears that the code is instantiating an instance of the Day class why isn’t the model just deserialsed into this instance?
  2. If for some other reason the proxy is necessary then can the above documentation please make this load and clear.

Brett

Thanks for your effort Brett, this is something that needs attention in some way or other.

A agree that the documentation could be clearer.

The reason for using a proxy is so that you could do e.g. day.setBooked(true) to also update the item in the server-side handler and have those changes show up in the browser. This requires either lots of expensive dirty checking or using a proxy where all setters are hooked up to mark which properties might have been updated.