vaadin 10 + Spring does not load custom-style.html

Hi everybody
I am using the vaadin base with spring project.
Vaadin 10 + Spring does not load custom-style.html when I navigate from a route (“login”) to route (“main-view”) that happens, however when loading only the main-view java class the styles work

@Route("main-view")
@PageTitle("My Starter Project")
@HtmlImport("frontend://styles/styles-combobox.html")
public class MainView extends VerticalLayout implements RouterLayout {
public MainView() {
		MyButton btnButton6=new MyButton();
        btnButton6.withCaption("Button Css buttonalerta");
        btnButton6.withStyle(Styles.BUTTON_ALERTA);
        btnButton6.setId("btn");
		add(btnButton6);
    }

}


Style

<dom-module id="vaadin-button-styles" theme-for="vaadin-button">
	<template>
		<style>
			:host(.buttonalerta){
				background-color: var(--color-rojo);
				box-shadow: 0 2px 5px 0 rgba( 0, 0, 0, 0.26);
			}
			:host(.buttonalerta) [part="label"]
, [part="prefix"]
, [part="suffix"]
{
				letter-spacing: .010em;
				font-size: 12px;
				font-weight: bold;
				text-transform: uppercase;
				color: var(--color-blanco);
			}
		</style>
	</template>
</dom-module>


My Login

@Route("login")
@PageTitle("My Starter Project")
public class LoginScreen extends FlexLayout {

    private TextField username;
    private PasswordField password;
    private Button login;
    private Button forgotPassword;

    public LoginScreen() {
        buildUI();
        username.focus();
    }
	
	.
	.
	.
	private void login() {
		getUI().get().navigate("main-view");
	}
}

17359610.png

Hi.

This is because @HtmlImport("frontend://styles/styles-combobox.html") is not imported for Login as it is only defined for MainLayout. If Login had @Route(value="login", layout=MainLayout.class) then the style would be imported for login also.

Your choices would thus be to add the styles import to Login or to have MainLayout only contain common things and have everything use it as a layout to get the same settings.

  • Mikael

Mikael Grankvist, Thank you. Works very well