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.

Comments:

Yeah Wicket is... Wicket. Makes me wonder why so many people are into JSF masochism, I guess they just haven't tried anything else. Making components in Wicket is a breeze in contrast.

Any chance perhaps of getting code completion for wicket in HTML files? (I have it on a TODO list but I keep adding more stuff to it than I remove.)

Posted by Casper Bang on December 08, 2008 at 04:43 AM PST #

Awesome post!, Wicket is really very powerful and great web framework and now is supported in Netbeans and is also as first class in Seam so bye bye JSF.

Posted by Otengi Miloskov on December 08, 2008 at 08:55 AM PST #

Hi Geertjan,
I have tried this tutorial, but it didn't work.It sames that the component didn't replied the countries we want.

Posted by Edward on December 08, 2008 at 11:14 AM PST #

Yupiii.. Slovenia is on the list :)

Posted by Kovica on December 08, 2008 at 01:15 PM PST #

Edward, I'd like to help you, but you really need to provide information or something so that I can do so.

Posted by Geertjan on December 08, 2008 at 06:44 PM PST #

hi,
the wicket plugin, although it is called Wicket 1.4 Support, it is still for wicket 1.3.3. Nevertheless, you have wicket 1.4 as an option in the wizard. What am I missing ?

Posted by no name on December 08, 2008 at 10:29 PM PST #

What do you mean? You get the 1.4 JARs, don't you?

Posted by Geertjan on December 08, 2008 at 10:50 PM PST #

well, I'm trying to get the 1.4 jars, yet I end up with the ones for 1.3 :). So the link is http://plugins.netbeans.org/PluginPortal/faces/PluginDetailPage.jsp?pluginid=3586, and there is only one download option.Maybe I'm missing a link or something, but I keep downloading \*1.3.3_plugin.zip. Sorry if there is something really obvious that escapes me.

Posted by no name on December 08, 2008 at 11:22 PM PST #

Refresh your browser, or maybe restart it completely. Because, I just tried it and downloaded something that included "1.4" in the zip's name.

Posted by Geertjan on December 08, 2008 at 11:34 PM PST #

As I suspected, I was missing something really obvious :) (although 3 browsers kept failing me). Anyway, thanks for your help and for your great work.

Posted by no name on December 09, 2008 at 12:16 AM PST #

Thanks a lot 'no name' and let me know how it works out for you.

Posted by Geertjan Wielenga on December 09, 2008 at 04:06 AM PST #

We're using Wicket and have found it great so far :-)

Posted by Andrew Humphries on December 09, 2008 at 01:35 PM PST #

Not to be off-topic, but following a link to a specific plugin has always lead to the front page of the plugin site -unless you click it twice!

Isn't it about time to poke the right guys and have them fix this rather silly behavior?

Posted by Casper Bang on December 11, 2008 at 03:05 AM PST #

Thank you for useful information

Posted by sinema izle on March 10, 2009 at 07:15 AM PDT #

The javascript behind the AutoCompleteTextField component fails in IE 7.0.6 (latest). Works fine in Firefox 3.0.6 :)

Posted by myles on April 28, 2009 at 04:34 PM PDT #

Thanks a lot 'no name' and let me know how it works out for you.

Posted by sinema izle on May 13, 2009 at 09:32 AM PDT #

good,thanks for sharing.

Posted by HD LCD monitor on July 19, 2009 at 01:54 PM PDT #

We're using Wicket and have found it great so far :-)

Posted by e-okul on January 13, 2010 at 08:15 AM PST #

Hi ,
I have s:file upload tag in my jsp.and one sx:autocompleter tag.
if i change the element in sx:autocompleter the ajax to work.
But the s:file tag is preventing not to work ajax properly.
Can you give me some idea.Pls…..
Im trying this for past one week…..
Thanks in advance.

Posted by swathi on June 26, 2011 at 08:51 PM PDT #

Post a Comment:
  • HTML Syntax: NOT allowed
About

Geertjan Wielenga (@geertjanw) is a Principal Product Manager in the Oracle Developer Tools group living & working in Amsterdam. He is a Java technology enthusiast, evangelist, trainer, speaker, and writer. He blogs here daily.

The focus of this blog is mostly on NetBeans (a development tool primarily for Java programmers), with an occasional reference to NetBeans, and sometimes diverging to topics relating to NetBeans. And then there are days when NetBeans is mentioned, just for a change.

Search

Archives
« April 2014
SunMonTueWedThuFriSat
  
12
13
14
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today