You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Stephan Koch <sk...@remove-n0spam.sk-dev.com> on 2008/05/12 11:27:55 UTC

Wicket Web Beans autocomplete field

Hi all,

I have a question regarding Wicket Web Beans (WWB). I know this may be
slightly OT, but since the wwb mailing list does not see a lot of
traffic these days, I figured I might as well post this here...

I introduced a new WWB field, basically an InputField with an added
AjaxAutocompleteBehavior (from wicket-contrib-scriptacolous). When I use
that field in a BeanForm, I have the following problem: When the user
selects a value from the autocomplete dropdown, the correcponding
InputField is correctly updated with the new value, then immediately
changes back to the old user input. About every 10th time or so it works
just fine...

Somehow the field value seems to refresh before the new autocompleted
value is written to the model. Any ideas on how to make this work correctly?

Thanks for the help...

-stephan


Code for the Autocomplete field is below, its just a slightly modified
InputField from wwb.

public abstract class AbstractAutoCompleteField extends AbstractField
{
     /**
      *
      * @param id the Wicket id for the editor.
      * @param model the model.
      * @param metaData the meta data for the property.
      * @param viewOnly true if the component should be view-only.
      */
     public AbstractAutoCompleteField(String id, IModel model,
ElementMetaData metaData, boolean viewOnly)
     {
         super(id, model, metaData, viewOnly);

         boolean advOnEnter = metaData.getBooleanParameter("advOnEnter");

         Fragment fragment;
         if (viewOnly) {
             fragment = new Fragment("frag", "viewer");
             fragment.add( new LabelWithMinSize("component", model) );
         }
         else {
             fragment = new Fragment("frag", "editor");

             TextField field = new TextField("component", model,
metaData.getPropertyType());
             AjaxAutocompleteBehavior acBehavior = new
AjaxAutocompleteBehavior() {
                 protected String[] getResults(String input) {
                     return getAutoCompleteResults(input);
                 }

             };
             field.add(acBehavior);

             if (advOnEnter) {
                 field.add( new SimpleAttributeModifier("onkeypress",
"return inputField_HandleEnter(this, event)") );
             }

             setFieldParameters(field);
             fragment.add(field);
         }

         add(fragment);
     }

     protected abstract String[] getAutoCompleteResults(String input);
}

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org