Access to template element from serverside

Hi!
How to access the template element (by the id attribute) from the java code on the server side?
In my case - how to access the elements inside the dom-repeat template (as shown below)?

<template>
	...
	<template is="dom-repeat" items="[[fuels]
]">
		<div id="fuel-[[item.id]
]">
			<div id="fuel-name-[[item.id]
]">[[item.name]
]</div>
			... some elements with ids ...
		</div>
	</template>
	...
</template>
public class FuelView extends PolymerTemplate<FuelView.MyModel> {
	@EventHandler
    void fireSomeButtonClick(...) {
		// Get access to fuel elements now...
		// As in the templatizer - find children by id (recursively)... but for templated element getChildren() is empty.
	}
}

If you have dom-repeat, you need to use @RepeatIndex annotation in your event handler, something like

public class FuelView extends PolymerTemplate<FuelView.MyModel> {
	@EventHandler
    void fireSomeButtonClick(@RepeatIndex int itemIndex) {
	     getModel().getFuels().get(itemIndex) ...
	}
}

Tatu Lund:

No, I don’t need access to the model data (it’s easy). I need to access the web elements (as com.vaadin.flow.dom.Element or vaadon flow Component) from java. When UI is generated programmatically from java, there are no problems with such access.

public class FuelView extends PolymerTemplate<FuelView.MyModel> {
	
	// for sample 
	void test() { 
	     getElementById("fuel-name-1").ifPresent(e -> {;
			 e.setEnabled(false);
			 e.getClassList().clear();
			 e.getThemeList().add("sometheme");
		 });
	}
	
	// Search by Id for all children... but FuelView is templated, shadowroot and childlist are empty!
	
	public Optional<Element> getElementById(String id) {
        if (id == null || !getElement().getShadowRoot().isPresent()) return Optional.empty();
        return getElement().getShadowRoot().get().getChildren().flatMap(this::flattenChildren)
                .filter((element) -> id.equals(element.getAttribute("id"))).findFirst();
    }

    private Stream<Element> flattenChildren(Element node) {
        return node.getChildCount() > 0 ? node.getChildren().flatMap(this::flattenChildren) : Stream.of(node);
    }
}