Skip to content

Commit 277130c

Browse files
javier-godoypaodb
authored andcommitted
refactor: use reflection for Vaadin 24 binary compatibility
1 parent a2729a6 commit 277130c

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

src/main/java/com/flowingcode/vaadin/addons/enhancedtabs/EnhancedTabs.java

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@
5050
import com.vaadin.flow.router.RouterLink;
5151
import com.vaadin.flow.shared.Registration;
5252
import java.io.Serializable;
53+
import java.lang.reflect.InvocationTargetException;
54+
import java.lang.reflect.Method;
55+
import java.lang.reflect.UndeclaredThrowableException;
5356
import java.util.ArrayList;
5457
import java.util.Iterator;
5558
import java.util.List;
@@ -198,6 +201,23 @@ public void add(Tab... tabs) {
198201
}
199202
}
200203

204+
private static final Method UI_navigate;
205+
static {
206+
try {
207+
UI_navigate = UI.class.getMethod("navigate", Class.class);
208+
} catch (NoSuchMethodException e) {
209+
throw new NoSuchMethodError("UI.navigate(Class)");
210+
}
211+
}
212+
213+
private static void navigate(UI ui, Class<? extends Component> target) {
214+
try {
215+
UI_navigate.invoke(ui, target);
216+
} catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
217+
throw new UndeclaredThrowableException(e);
218+
}
219+
}
220+
201221
public RouterLink addRouterLink(String text, Class<? extends Component> target) {
202222
RouterLink routerLink = new RouterLink(text, target);
203223
routerLink.getElement().executeJs(
@@ -207,7 +227,7 @@ public RouterLink addRouterLink(String text, Class<? extends Component> target)
207227
"});\n");
208228

209229
routerLink.getElement().addEventListener("client-side-click", event -> {
210-
UI.getCurrent().navigate(target);
230+
navigate(UI.getCurrent(), target);
211231
});
212232

213233
add(new Tab(routerLink));

0 commit comments

Comments
 (0)