diff --git a/src/main/java/com/penguineering/gartenplus/ui/appframe/ForwardingPage.java b/src/main/java/com/penguineering/gartenplus/ui/appframe/ForwardingPage.java new file mode 100644 index 0000000..105a6c3 --- /dev/null +++ b/src/main/java/com/penguineering/gartenplus/ui/appframe/ForwardingPage.java @@ -0,0 +1,26 @@ +package com.penguineering.gartenplus.ui.appframe; + +import com.vaadin.flow.component.Component; +import com.vaadin.flow.component.Tag; +import com.vaadin.flow.router.BeforeEnterEvent; +import com.vaadin.flow.router.BeforeEnterObserver; + +import java.util.Objects; + +/** + * A page that forwards to another page. + */ +@Tag("div") +public abstract class ForwardingPage extends Component implements BeforeEnterObserver { + private final Class target; + + public ForwardingPage(Class target) { + Objects.requireNonNull(target, "target must not be null"); + this.target = target; + } + + @Override + public void beforeEnter(BeforeEnterEvent event) { + event.forwardTo(this.target); + } +} diff --git a/src/main/java/com/penguineering/gartenplus/ui/content/accounting/AccountingPage.java b/src/main/java/com/penguineering/gartenplus/ui/content/accounting/AccountingPage.java index 873d72b..bb47868 100644 --- a/src/main/java/com/penguineering/gartenplus/ui/content/accounting/AccountingPage.java +++ b/src/main/java/com/penguineering/gartenplus/ui/content/accounting/AccountingPage.java @@ -1,5 +1,6 @@ package com.penguineering.gartenplus.ui.content.accounting; +import com.penguineering.gartenplus.ui.appframe.ForwardingPage; import com.penguineering.gartenplus.ui.appframe.GartenplusPage; import com.penguineering.gartenplus.ui.content.accounting.myfinances.MyFinancesPage; import com.vaadin.flow.router.BeforeEnterEvent; @@ -11,10 +12,8 @@ @Route(value = "", layout = AccountingLayout.class) @PermitAll @PageTitle("GartenPlus | Buchhaltung") -public class AccountingPage extends GartenplusPage implements BeforeEnterObserver { - @Override - public void beforeEnter(BeforeEnterEvent event) { - - event.getUI().navigate(MyFinancesPage.class); +public class AccountingPage extends ForwardingPage { + public AccountingPage() { + super(MyFinancesPage.class); } } diff --git a/src/main/java/com/penguineering/gartenplus/ui/content/admin/settings/SettingsPage.java b/src/main/java/com/penguineering/gartenplus/ui/content/admin/settings/SettingsPage.java index 3c1b84c..9cf728a 100644 --- a/src/main/java/com/penguineering/gartenplus/ui/content/admin/settings/SettingsPage.java +++ b/src/main/java/com/penguineering/gartenplus/ui/content/admin/settings/SettingsPage.java @@ -1,9 +1,7 @@ package com.penguineering.gartenplus.ui.content.admin.settings; -import com.penguineering.gartenplus.ui.appframe.GartenplusPage; +import com.penguineering.gartenplus.ui.appframe.ForwardingPage; import com.penguineering.gartenplus.ui.content.admin.settings.users.UsersSettingsPage; -import com.vaadin.flow.router.BeforeEnterEvent; -import com.vaadin.flow.router.BeforeEnterObserver; import com.vaadin.flow.router.PageTitle; import com.vaadin.flow.router.Route; import jakarta.annotation.security.RolesAllowed; @@ -11,10 +9,8 @@ @Route(value = "", layout = SettingsLayout.class) @RolesAllowed("ADMINISTRATOR") @PageTitle("GartenPlus | Einstellungen") -public class SettingsPage extends GartenplusPage implements BeforeEnterObserver { - @Override - public void beforeEnter(BeforeEnterEvent event) { - - event.getUI().navigate(UsersSettingsPage.class); +public class SettingsPage extends ForwardingPage { + public SettingsPage() { + super(UsersSettingsPage.class); } }