Skip to content

Commit

Permalink
Merge pull request #29 from penguineer/forwarding-method
Browse files Browse the repository at this point in the history
Add a ForwardingPage base class and use forwardTo for forwarding to sub-pages
  • Loading branch information
penguineer authored Aug 5, 2024
2 parents aba6b72 + d0cc311 commit 3113026
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 13 deletions.
Original file line number Diff line number Diff line change
@@ -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<? extends Component> target;

public ForwardingPage(Class<? extends Component> target) {
Objects.requireNonNull(target, "target must not be null");
this.target = target;
}

@Override
public void beforeEnter(BeforeEnterEvent event) {
event.forwardTo(this.target);
}
}
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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);
}
}
Original file line number Diff line number Diff line change
@@ -1,20 +1,16 @@
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;

@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);
}
}

0 comments on commit 3113026

Please sign in to comment.