Use binder and editor on grid without bean type - Vaadin 14

Hello! I’m using a grid whose type is an ArrayList < object> because I’m getting the columns from a json. When I try to use the editor and binder for inline editing I’m getting this exception "java.lang.IllegalStateException: This Binder instance was created using the default constructor. To be able to use property names and bind to instance fields, create the binder using the Binder(Class beanType) constructor instead. ". I’m using an object with unknown structure at the compiletime so I can’t access the properties. So how can i do inline editing in this case?

You can’t. At least not with items of type ArrayList<Object> as there is no way to know which listItem correlates to which column. I’d be interested to see how you implemented your Grid up to this point, especially how you add the columns. I’m probably missing some key information.

If you had items of type Map<String, Object> where the string is the column key and the object is the value of that item for said column, this would be a different story. You could then create the editor TextFields like this:

TextField editorTextField = new TextField();
// editorBinder is of type Binder<Map<String, Object>>
	item -> item.get("fooBarColumn"),
	(item, value) -> item.put(value)

This hopefully makes clear why I instinctly would store column information inside the generic item structure.
If you tell me how you add your columns in the first place, I might be able to find a way to do the same without column information.

PS: My code is untested. I am not 100% this would work but I don’t see why it wouldn’t. Just be aware that this will only edit the generified item that you use for presentation, and not the actual bean itself that you used to create an ArrayList<Object> thereof.

Edit: it seems to me that this is exactly what you want - to alter the actual bean. This is not going to be possible without information about which property/field a certain value represents. When you have an ArrayList<Object>, how will you know which object-value belongs to which property of your bean? answer: you won’t.

This is not the only problem with this. From your generic grid-item structure, there is no way in getting the right original bean. You can convert any bean into an ArrayList<Object>, but this arraylist has no information/relation to the original bean.
This obstacle could also be circumvented by changing the generified item structure to Map<String, Object> because in addition to Map.Entrys for each column, you can also add another mapentry to hold the original bean, which is not going to be displayed in the grid. While this does not solve the first problem (not knowing which field/property a column refers to), it does solve the problem of getting back an original bean from a generified one.
I am positive that the first problem is not unsolvable, but any solution will involve knowing the corresponding bean-property on a column (or generic item).

I am currently implementing a generic Grid myself but haven’t gotten to the point of editing. I will update if/when I find an acceptable solution