Overriding error messages from ApplicationConnection class

We override error messages (like Communication problem. Take note of any unsaved data, and click here to continue, Session expired…) from com.vaadin.terminal.gwt.server.AbstractApplicationServlet#getSystemMessages(). But some additional information appear in that messages for example : “Invalid status code 0 (server down?)”. We know that this messages are hardcoded in com.vaadin.terminal.gwt.client.ApplicationConnection class. Is there any way to override this strings or we have to change this in Vaadin sources?

Hi Ann,

If you just want to get rid of that additional information then you could just hide the element with CSS.

.v-Notification-system p+br+p {
display: none;
}

Currently there isn’t clean way for overriding those client side error messages.

Quick kludge would be to copy paste that ApplicationConnection to some MyApplicationConnection and let gwt replace that class by defining

<replace-with class="com.myproject.gwt.client.MyApplicationConnection>

Created ticket
http://dev.vaadin.com/ticket/7181
for customizing client-side messages.

Ok… I found what I would consider a bug…

ApplicationConnection. showError will skip the notification and go straight to the url if caption & message are null.
This is in alignment with the JavaDOC at CustomizableSystemMessages.setNotificationEnabled(false) which sets message & caption = null

However, AbstractApplicationServer.criticalNotification(…) set message = details if message is null

Therefore message will never be equal to null.

This is my fix, only add details if either caption or message is not null… If they are both null, we send null.


ApplicationConnection. showError
Notice that if caption & message are null it skips the notification

    private void showError(String details, String caption, String message,
            String url) {

        StringBuilder html = new StringBuilder();
        if (caption != null) {
            html.append("<h1>");
            html.append(caption);
            html.append("</h1>");
        }
        if (message != null) {
            html.append("<p>");
            html.append(message);
            html.append("</p>");
        }

        if (html.length() > 0) {

            // Add error description
            html.append("<br/><p><I style=\"font-size:0.7em\">");
            html.append(details);
            html.append("</I></p>");

            VNotification n = new VNotification(1000 * 60 * 45);
            n.addEventListener(new NotificationRedirect(url));
            n.show(html.toString(), VNotification.CENTERED_TOP,
                    VNotification.STYLE_SYSTEM);
        } else {
            redirect(url);
        }
    }


AbstractApplicationServer.criticalNotification

    

  protected void criticalNotification(HttpServletRequest request,
            HttpServletResponse response, String caption, String message,
            String details, String url) throws IOException {

        if (isUIDLRequest(request)) {

        	if (caption != null || message != null){
	            if (caption != null) {
	                caption = "\"" + JsonPaintTarget.escapeJSON(caption) + "\"";
	            }
	            if (details != null) {
	                if (message == null) {
	                    message = details;
	                } else {
	                    message += "<br/><br/>" + details;
	                }
	            }
        	}

       ......

I just tried to override the class as Mauno suggested. I just simply add showError always redirect.

But when I load any page it just spins indefinitely.

I also tried reverting my change so my class was identical to ApplicationConnection** and it still hangs…
(** except it subclasses ApplicationConnection and prefixes “this” with it’s class name instead of ApplicationContext)

I can toggle the in and out and it will cause the app to hang…
I have this under modules in my gwt.xml file

 <replace-with class="com.vaadin.terminal.gwt.client.DexApplicationConnection"> 
	<when-type-is class="com.vaadin.terminal.gwt.client.ApplicationConnection"/>
</replace-with> 

Douglas