Skip to content

Instantly share code, notes, and snippets.

@mstahv
Created March 21, 2016 10:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mstahv/ddbfc671351cf3dfa3ac to your computer and use it in GitHub Desktop.
Save mstahv/ddbfc671351cf3dfa3ac to your computer and use it in GitHub Desktop.
Example how to add lang attribute to Vaadin app
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