Monthly Archives: February 2013

Auto adjust Grid

If you have a Grid within a Panel or Window class and the Grid will not be automatically adjusted, you will have to check the complete widget hierarchy for valid LayoutManagers. All parent widgets of the Grid must use the layout sytem. Then we can use

  grid.getView().setAutoFill(true);
  grid.getView().setForceFit(true);

The parent Panel or Window should define an minimal height and width.

  window.setLayout(new FitLayout());
  window.setMinWidth(500);
  window.setMinHeight(400);

Every resize operation on the Panel/Window should resize the Grid too. If you forget the layout on the window or its panels, the grid will not be displayed till you set a height and width explicitly.

Wrong charset with GWT Dev-Mode in Eclipse

If you use .properties files to define the application strings, you will run into a strange behaviour of the GWT Dev-Mode in Eclipse.

All .properties files have a default charset of ISO-8859-1. You can see that on your global preferences:

eclipse-prefs

If you write your text, it will be encoded into ISO-8859-1. Now the internal Jetty sends HTTP responses with a charset ISO-8859-1, your text will be unchanged. But if the browser displays the website in UTF-8, all of your texts have the wrong charset (i.e. German umlaute will be wrong). There is no config option to change the behaviour of the Jetty, but you can set the default charset of the .properties files to UTF-8. Then the HTTP responses will change your text encoding, but the browser will change it back to the right charset (set Content-type UTF-8 within your index.html!).

Set focus on a textfield to prevent validation

In the SignInWindow of the trial registry the login textfield has always a red border, because it executes the validation (must not empty) too earlier. So it is necessary to set the focus on that textfield, if we open the window. The following code is copied from the Sencha forum:

Window window = new Window();
window.setWidth(400);
FormPanel formPanel = new FormPanel();                 
                
TextField<String> passwordField = new TextField<String>();                
passwordField.setFieldLabel("xyz");
passwordField.setEmptyText("abcd");
passwordField.setAllowBlank(false);    
passwordField.setMaxLength(255);
passwordField.setPassword(true);
// passwordField.focus(); - Comment this
                
formPanel.add(passwordField);
window.add(formPanel);

window.setFocusWidget(passwordField); // Added this line
window.show();

It doesn’t work to set focus() on the textfield, it is better to let the window decide that.

GXT webdesktop – no background image

If you don’t see the background image of your Desktop, your website probably don’t load the associated CSS files. First at all, you have to include the CSS into your start page:


<link type="text/css" rel="stylesheet" href="gxt-2.2.5/css/gxt-all.css">
<link type="text/css" rel="stylesheet" href="gxt-2.2.5/desktop/css/desktop.css">

Start your appliaction in Development Mode, and open the start page in your browser. If there isn’t the background image visible, you should check your page with a debug-tool like Firebug. Navigate to the CSS link (mostly in <head>) and try to open the link. If the file could not be found (you can not see the CSS definitions), your GXT resources are not available within the application. Copy the necessary files into your WAR or in your deployment directory.