Daily Archives: February 14, 2013

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.