Important Notice - Forums is archived
To simplify things and help our users to be more productive, we have archived the current forum and focus our efforts on helping developers on Stack Overflow. You can post new questions on Stack Overflow or join our Discord channel.

Vaadin lets you build secure, UX-first PWAs entirely in Java.
Free ebook & tutorial.
Application specific error pages
Hi,
After doing some research, I found out how to enable custom error pages at WAR level. I have created a sample app to test things a bit (sources bellow). In the configuration changes I have made, everything seems to work as desired except at one point. The look and feel of the custom error page seems to be overruled by Vaadin theming. I suppose this is caused by the fact the exception is thrown from within the init-method.
The question is, how can I overrule the Vaadin theme from being applied when a custom error page needs to be displayed to the user. Thank you for reading my question!
Regards,
Kurt
Bellow you will find the different sources of the sample application and the corresponding configuration changes.
First the VaadinServlet class is defined as bellow.
@WebServlet(urlPatterns = {"/ui/*", "/VAADIN/*"},
name = "MyUIServlet",
asyncSupported = true)
@VaadinServletConfiguration(ui = MyUI.class,
productionMode = false)
public class MyUIServlet extends VaadinServlet{
}
The corresponding UI class does the following.
@Theme("mytheme")
public class MyUI extends UI {
@Override
protected void init(VaadinRequest vaadinRequest) {
VerticalLayout layout = new VerticalLayout();
layout.setMargin(true);
layout.setSpacing(true);
setContent(layout);
TextField name = new TextField();
name.setCaption("The application has started");
layout.addComponents(name);
throw new MissingResourceException("Wepaaaaah",
MyUI.class.getSimpleName(),
"test");
}
}
In actual code the MissingResourceException would e.g. be thrown when a JNDI look-up fails. Since this is considered an irrecoverable error, a custom error page might be usefull for the user, together with some server-side logging.
To enable the custom error page, the following web.xml has been added to the WAR.
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
version="3.0">
<session-config>
<session-timeout>
30
</session-timeout>
</session-config>
<error-page>
<error-code>500</error-code>
<location>/error/500.html</location>
</error-page>
</web-app>
Finally, the custom error page
<html>
<head>
<title>HTTP 500 Error</title>
<meta charset="UTF-8">
</head>
<body style="background-color: #212121; color=#F4671F; width:100%; height:100%;">
<div style="text-align:center; font-size:36px;">
Woops something went wrong
</div>
</body>
</html>
When the WAR is deployed (Glassfish 4.1) the 'displayed' (see attachments) is shown while the expected layout should be expected.png. Clearly, some layout styles are overruled...
The attachments mentionned in previous post.