Download NetBeans!

20081208 Monday December 08, 2008

AJAX: Can it get better than this...

...if so, I'd like to know:

  1. Go here and download the ZIP file that you find there (updated 5 seconds ago):

    http://plugins.netbeans.org/PluginPortal/faces/PluginDetailPage.jsp?pluginid=3586

    Use the NetBeans Plugin Manager to install the 3 NBMs that are contained within that ZIP file.

  2. Create a new web application and, in the final panel, click the Wicket checkbox:

    Click Finish and then you'll have a completely new & fresh Wicket application, with all its standard bells & whistles:

  3. The "HomePage" will be open, enticing you to put something there. So make it this:
    public class HomePage extends BasePage {
    
        public HomePage() {
    
            add(field);
    
        }
        
        final AutoCompleteTextField field = new AutoCompleteTextField("countries", new Model("")) {
    
            @Override
            protected Iterator getChoices(String input) {
                if (Strings.isEmpty(input)) {
                    return Collections.EMPTY_LIST.iterator();
                }
                List choices = new ArrayList(10);
                Locale[] locales = Locale.getAvailableLocales();
                for (int i = 0; i < locales.length; i++) {
                    final Locale locale = locales[i];
                    final String country = locale.getDisplayCountry();
                    if (country.toUpperCase().startsWith(input.toUpperCase())) {
                        choices.add(country);
                        if (choices.size() == 10) {
                            break;
                        }
                    }
                }
                return choices.iterator();
            }
        };
        
    }

  4. Add the Java component's HTML counterpart on the other side:

    <input type="text" wicket:id="countries" size="50"/>

  5. Run the application and you're done:

    You now have an autocomplete textfield powered by AJAX.

Ask yourself:

  1. How much JavaScript did you need to know? (Thanks, Wicket! Then read all about it here.)

  2. How much Wicket did you need to know? (Thanks, NetBeans IDE! Then read all about it here.)

If you like this stuff, track this issue, which seeks to include the Wicket plugin in the NetBeans Update Center:

http://www.netbeans.org/issues/show_bug.cgi?id=153152

Three issues: you must right-click a package (not the project) when using the Wicket file templates; don't try to use the Project Properties dialog to add/remove Wicket support; the "Login" sample has issues, though the "Pizza" sample doesn't. For the rest, this plugin should work fine.

Dec 08 2008, 11:52:25 AM PST Permalink