Get object in component renderer grid

Hi everyone.
I’ve create detail in my grid with a component renderer thanks to the doc https://vaadin.com/docs/latest/components/grid
Instead of a form like in the example I’ve created an other grid in this detail.

I would like to retrieve the object created to handle this in my principal grid.
How can I get the object ? Thanks in advance for your help.

You could simply store the object in a member variable. What did you try so far?

Thank you for your help but that is the code I use to create my renderer

myPrincipalGrid.setItemDetailsRenderer(createPersonDetailsRenderer());

private static ComponentRenderer<GridPersonDetail, PersonDetail> createPersonDetailsRenderer()
		{
	        return new ComponentRenderer<>(GridPersonDetail::new, GridPersonDetail::setPersonDetail);
	    }
	

How I can extract the object “GridPersonDetail” from the ComponentRenderer to store it ?

What is GridPersonDetail and PersonDetail?

MyPrincipalGrid is a list of “PersonDetail”.
And in that grid I have an item who contain a grid “GridPersonDetail”.
But we can choose the example for my problem in the doc https://vaadin.com/docs/latest/components/grid in the “item Details” part.
How I can I store in a variable the “PersonDetailsFormLayout” ?

You may want to look into the constructor
ComponentRenderer(SerializableFunction<SOURCE, COMPONENT> componentFunction)

and use it like this

private static ComponentRenderer<GridPersonDetail, PersonDetail> createPersonDetailsRenderer() {
  return new ComponentRenderer<>(personDetail -> {
    var layout = new GridPersonDetail();
    layout.setPersonDetail(personDetail);
    // TODO store layout
    return layout;
  });
}

You probably don’t want the static keyword in the method there in case you want to store a local reference.

Ok, I didn’t know that we can update the constructor like that. Thank you it works. ;-)

1 Like