-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #29 from penguineer/forwarding-method
Add a ForwardingPage base class and use forwardTo for forwarding to sub-pages
- Loading branch information
Showing
3 changed files
with
34 additions
and
13 deletions.
There are no files selected for viewing
26 changes: 26 additions & 0 deletions
26
src/main/java/com/penguineering/gartenplus/ui/appframe/ForwardingPage.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 4 additions & 8 deletions
12
src/main/java/com/penguineering/gartenplus/ui/content/admin/settings/SettingsPage.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |