Hi,

I
would like to add AJAX behavior to an application that sends an update
to my application after a certain number of characters have been typed.
For example, if the user is entering a zipcode, I would like a callback
to my application to be made after the user enters the fifth character.

I've
written code using OnChangeAjaxBehavior that sends messages back to my
application after every character has been typed, such as the following:

    final TextField<String> zipcodeField = new TextField<String>( "zipcode" );
    form.add( zipcodeField.setRequired( true ) );
    OnChangeAjaxBehavior zipcodeUpdated = new OnChangeAjaxBehavior() {
      @Override
      protected void onUpdate( AjaxRequestTarget target ) {
        System.out.println( "Zipcode value: " + 
zipcodeField.getDefaultModelObjectAsString() );
      }
    };
    zipcodeField.add( zipcodeUpdated );


I
could check to see the size of the zipcodeField (in this example), but
it makes my application more chatty than it needs to be. I also tried
using onblur, which works fine, but does not satisfy my business
requirements:

  final TextField<String> zipcodeField = new TextField<String>( "zipcode" );
  form.add( zipcodeField.setRequired( true ) );

  AjaxFormComponentUpdatingBehavior zipcodeOnBlur = new 
AjaxFormComponentUpdatingBehavior( "onblur" ) {
      @Override
      protected void onUpdate( AjaxRequestTarget target ) {
          System.out.println( "Zipcode value (form component): " + 
getFormComponent().getModelObject() );
      }
  };
  zipcodeField.add( zipcodeOnBlur );



Prior
to using Wicket (which I'm currently prototyping for my company), we
would handle this logic in JavaScript (observe changes to the field and
when the user enters the fifth character then we made an AJAX call back
our Struts 2 application.) 

What is the best way to achieve the same end using Wicket?

Thanks, in advance, for your help!
Steve

P.S.
I started using Wicket as part of an article series (because of all of
your passion for it) and I have to say all of you are doing incredible
work - I love it.. Here's the link to the article series in case any of
you are interested:
http://www.informit.com/guides/content.aspx?g=java&seqNum=529

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to