-
Notifications
You must be signed in to change notification settings - Fork 45
Vaadin 8 | Spring
When using SpringViews
it is required to set AppLayoutBuilder::withCDI(true)
.
Also it is necessary to inject a custom Navigator
or a ViewProvider
into the AppLayout
. This can be done via AppLayoutBuilder::withNavigatorProducer
as to be seen in the code example below.
@SpringUI
@Viewport("initial-scale=1, maximum-scale=1")
@Theme("mytheme")
public class MyUI extends UI {
@Autowired
SpringNavigator navigator;
@Override
protected void init(VaadinRequest vaadinRequest) {
setContent(AppLayoutBuilder.get(Behaviour.LEFT_RESPONSIVE_HYBRID)
.withTitle("Appbar Demo")
.withDesign(AppBarDesign.MATERIAL)
.withCDI(true)
.withAppBarIconComponent(new RoundImage(new ThemeResource("logo.png")))
.withNavigationElementInfoProvider(new DefaultSpringNavigationElementInfoProvider())
.add(new MenuHeader("App-Layout", "0.9.14", new ThemeResource("logo.png")), HEADER)
.add(FirstView.class)
.add(SecondView.class)
.add(SubmenuBuilder.get("Submenu", VaadinIcons.FILE_TREE)
.add(ThirdView.class)
.add(SubmenuBuilder.get("SubSubMenu", VaadinIcons.FILE_TREE)
.add(FourthView.class)
.build())
.add(FifthView.class)
.build())
.addClickable("Click Me", VaadinIcons.QUESTION, clickEvent -> {/*Click Event*/})
.add(SixthView.class, FOOTER)
.withNavigatorProducer(components -> {
navigator.init(this, components);
navigator.setErrorView(ErrorView.class);
return navigator;
})
.build()
);
}
}
The Default View always has a @SpringView(name = "")
. If the User navigates to the default path http://my-website.com/
this View will be shown. The Annotations @MenuCaption("Home")
and @MenuIcon(VaadinIcons.HOME)
are optional and can be used to set name and the icon for the menu entry that is generated for this view.
To make them have an effect you need to set:
AppLayoutBuilder::withNavigationElementInfoProvider(new DefaultSpringNavigationElementInfoProvider())
@SpringView(name = "")
@MenuCaption("Home")
@MenuIcon(VaadinIcons.HOME)
public class FirstView extends VerticalLayout implements View {
...
}
Other Views always require to have a unique @SpringView(name = "<my-path>")
.
If the User navigates to the path http://my-website.com/<my-path>
this View will be shown.
@SpringView(name = "second")
@MenuCaption("Charts")
@MenuIcon(VaadinIcons.SPLINE_CHART)
public class SecondView extends VerticalLayout implements View {
...
}