Section 8.7. Displaying User Messages

8.7. Displaying User Messages

I created a utility class called RpcStatus, which is used to show messages inside one of two div tags. One div is designed for informational messages, the other for errors or exceptions. Figure 9 shows an informational message and an error message.

Figure 8-4. An Ajax application shows an error message because the server is down

Here is the source code for that utility class.

 package com.parkerriver.gwt.intro.client; import; import; /**  * A utility class for displaying messages  */ public class RpcStatus {   private String statusDivId;   public RpcStatus() {       this("status");   }   public RpcStatus(String statusDivId) {       this.statusDivId = statusDivId;   }   public String getStatusDivId() {       return statusDivId;   }   public void setStatusDivId(String statusDivId) {       this.statusDivId = statusDivId;   }   public void showStatus(boolean _on, String message,                          String color){       Element el = DOM.getElementById(getStatusDivId());       if(el != null)  {           if(_on) {               DOM.setStyleAttribute(el,"font-size","1.2em");               if(color == null || color.length() < 1) {                   DOM.setStyleAttribute(el,"color","purple");               } else {                   DOM.setStyleAttribute(el,"color",color);               }               if(message == null || message.equalsIgnoreCase("")){                   DOM.setInnerHTML(el,                           "");               } else {                   DOM.setInnerHTML(el, message);               }           }  else{               DOM.setInnerHTML(el, "");           }       }   } } 

One interesting aspect of this class is that it uses the object to implement the kind of classic Ajaxy programming we are all fond of, using familiar DOM API methods such as getElementById(), and techniques such as setting an element's innerHTML property (using the method DOM.setInnerHTML()).

The source code for displaying the error message in Figure 9 is:

 status.setStatusDivId("err_message"); status.showStatus(true, "The server appears to be unavailable right now."+ " Please try again iin a moment.", "red"); 

Google Web Toolkit for Ajax
Google Web Toolkit GWT Java AJAX Programming: A step-by-step to Google Web Toolkit for creating Ajax applications fast
ISBN: 1847191002
EAN: 2147483647
Year: 2006
Pages: 29 © 2008-2017.
If you may any questions please contact us: