Created
March 21, 2016 10:03
-
-
Save mstahv/ddbfc671351cf3dfa3ac to your computer and use it in GitHub Desktop.
Example how to add lang attribute to Vaadin app
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
package org.test; | |
import javax.servlet.annotation.WebServlet; | |
import com.vaadin.annotations.Theme; | |
import com.vaadin.annotations.VaadinServletConfiguration; | |
import com.vaadin.server.BootstrapFragmentResponse; | |
import com.vaadin.server.BootstrapListener; | |
import com.vaadin.server.BootstrapPageResponse; | |
import com.vaadin.server.VaadinRequest; | |
import com.vaadin.server.VaadinServlet; | |
import com.vaadin.ui.Label; | |
import com.vaadin.ui.UI; | |
import javax.servlet.ServletException; | |
/** | |
* A UI example to set lang attr to document element | |
*/ | |
@Theme("mytheme") | |
public class MyUI extends UI { | |
@Override | |
protected void init(VaadinRequest vaadinRequest) { | |
setContent(new Label("Hello lang attr")); | |
} | |
@WebServlet(urlPatterns = "/*", name = "MyUIServlet", asyncSupported = true) | |
@VaadinServletConfiguration(ui = MyUI.class, productionMode = false) | |
public static class MyUIServlet extends VaadinServlet { | |
@Override | |
protected void servletInitialized() throws ServletException { | |
super.servletInitialized(); | |
getService().addSessionInitListener(e -> | |
e.getSession().addBootstrapListener(new BootstrapListener() { | |
@Override | |
public void modifyBootstrapFragment( | |
BootstrapFragmentResponse response) { | |
// NOP, this is for portlets etc | |
} | |
@Override | |
public void modifyBootstrapPage( | |
BootstrapPageResponse response) { | |
response.getDocument().child(0).attr("lang", "fr"); | |
} | |
}) | |
); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment